相关疑难解决方法(0)

使用scikit-learn分类为多个类别

我正在尝试使用scikit-learn的监督学习方法之一将文本片段分类为一个或多个类别.我尝试的所有算法的预测函数只返回一个匹配.

例如,我有一段文字:

"Theaters in New York compared to those in London"
Run Code Online (Sandbox Code Playgroud)

我已经训练了算法为我提供的每个文本片段选择一个地方.

在上面的例子中,我希望它返回New YorkLondon,但它只返回New York.

是否可以使用scikit-learn返回多个结果?或者甚至以最高概率返回标签?

谢谢你的帮助.

---更新

我尝试过使用,OneVsRestClassifier但我仍然只能在每段文字中找到一个选项.下面是我正在使用的示例代码

y_train = ('New York','London')


train_set = ("new york nyc big apple", "london uk great britain")
vocab = {'new york' :0,'nyc':1,'big apple':2,'london' : 3, 'uk': 4, 'great britain' : 5}
count = CountVectorizer(analyzer=WordNGramAnalyzer(min_n=1, max_n=2),vocabulary=vocab)
test_set = ('nice day in nyc','london town','hello welcome to the big apple. enjoy it here and london too')

X_vectorized = …
Run Code Online (Sandbox Code Playgroud)

python classification scikit-learn

77
推荐指数
4
解决办法
6万
查看次数

标签 统计

classification ×1

python ×1

scikit-learn ×1