哪种算法用于一个类别分类?

ada*_*dam 6 scikit-learn text-classification

我有超过15000个特定主题的文本文档.我想建立一个基于前者的语言模型,以便我可以向该模型呈现各种主题的新随机文本文档,并且算法会告诉新文档是否属于同一主题.

我尝试了sklearn.naive_bayes.MultinomialNB,sklearn.svm.classes.LinearSVC其他人,但我有以下问题:

这些算法需要具有多个标签或类别的培训数据,并且我只有涵盖特定主题的网页.其他文档没有标注,也没有许多不同的主题.

对于如何仅使用一个标签培训模型或如何进行一般操作,我将不胜感激.到目前为止我所拥有的是:

c = MultinomialNB()
c.fit(X_train, y_train)
c.predict(X_test)
Run Code Online (Sandbox Code Playgroud)

非常感谢你.

Mat*_*att 9

您正在寻找的是OneClassSvm.有关更多信息,您可能需要查看此链接中的相应文档.


小智 6

TextBlob模块中有另一个可用的分类器,称为PositiveNaiveBayesClassifier。引用他们的文档:

朴素贝叶斯分类器的一种变体,它使用部分标记的训练集执行二元分类,即当只有一个类被标记而另一个没有被标记时。假设两个标签上的先验分布,使用未标记的集合来估计特征的频率。

代码用法:

>>> from text.classifiers import PositiveNaiveBayesClassifier
>>> sports_sentences = ['The team dominated the game',
                        'They lost the ball',
                        'The game was intense',
                        'The goalkeeper catched the ball',
                        'The other team controlled the ball']
>>> various_sentences = ['The President did not comment',
                         'I lost the keys',
                         'The team won the game',
                         'Sara has two kids',
                         'The ball went off the court',
                         'They had the ball for the whole game',
                         'The show is over']
>>> classifier = PositiveNaiveBayesClassifier(positive_set=sports_sentences,
                                unlabeled_set=various_sentences)
>>> classifier.classify("My team lost the game")
True
>>> classifier.classify("And now for something completely different.")
False
Run Code Online (Sandbox Code Playgroud)