Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用TextBlob获得新短语的准确性?_Python_Nltk_Textblob - Fatal编程技术网

Python 如何使用TextBlob获得新短语的准确性?

Python 如何使用TextBlob获得新短语的准确性?,python,nltk,textblob,Python,Nltk,Textblob,我正在使用NaiveBayes模型制作一个分类器,对用户的位置、天气等请求进行分类 我返回的分类如下所示: ("What is the weather in Copenhagen", "weather") 然后对这些请求进行训练,并与返回准确度的测试集进行比较。这是一个很好的工作 c = NaiveBayesClassifier(train_set) self.classifier = Blobber(analyzer=NaiveBayesAnalyzer(), classifier=c) p

我正在使用NaiveBayes模型制作一个分类器,对用户的位置、天气等请求进行分类

我返回的分类如下所示:

("What is the weather in Copenhagen", "weather")
然后对这些请求进行训练,并与返回准确度的测试集进行比较。这是一个很好的工作

c = NaiveBayesClassifier(train_set)
self.classifier = Blobber(analyzer=NaiveBayesAnalyzer(), classifier=c)
print(c.accuracy(test_set))
我正在运行此方法对新短语进行分类

    def classify_phrase(self, tb_phrase):
        return self.classifier(tb_phrase).classify()
然而,当我尝试对一个不属于我的分类或是用户错误的新短语进行分类时,它仍然尝试将其分类为请求。示例如下:

("Where is Bob", "location")

这将返回一个错误,但不会返回。有没有办法从新输入的短语的Textblob中获得准确度?因此,当我输入一个短语时,它将告诉我该短语的准确性。我正在使用Textblob包和Python 3。如果需要更多信息,完整代码位于我的计算机上的NaturalLanguage.py文件下。提前谢谢。

我使用textBlob中的prob_分类方法解决了自己的问题。这将返回给定分类的概率。短语是字符串,分类是朴素贝叶斯分类器的集体行为

    def classifier_prob(self, phrase, classification):
         return self.classifier.prob_classify(phrase).prob(classification)