【问题标题】:How to get the accuracy of new phrases with TextBlob?如何使用 TextBlob 获得新短语的准确性?
【发布时间】:2017-09-25 10:01:02
【问题描述】:

我正在使用 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。如果需要更多信息,完整代码位于我的 GitHub 上的 NaturalLanguage.py 文件下。提前谢谢你。

【问题讨论】:

    标签: python nltk textblob


    【解决方案1】:

    我使用 textBlob 中的 prob_classify 方法解决了我自己的问题。这将返回给定分类的概率。短语是一个字符串,分类是来自 NaiveBayes 分类器的集体行动。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-01
      • 2018-12-05
      • 1970-01-01
      • 2020-06-01
      • 2017-11-10
      • 2017-09-21
      • 2017-06-25
      • 1970-01-01
      相关资源
      最近更新 更多