代码之家  ›  专栏  ›  技术社区  ›  Razan Balatiah

我使用python 3.6,我想进行情绪分析,但nltk中有一个错误。指标包?[副本]

  •  1
  • Razan Balatiah  · 技术社区  · 7 年前

    我在这里编写代码:

        print ('pos precision:', nltk.metrics.precision(refsets['pos'], 
        testsets['pos']))
        print ('pos recall:', nltk.metrics.recall(refsets['pos'], 
        testsets['pos']))
    

    输出如下:

       line 35, in evaluate_classifier
       print ('pos precision:', nltk.metrics.precision(refsets['pos'], 
       testsets['pos']))
       AttributeError: module 'nltk.translate.metrics' has no attribute 
      'precision'
    

    如何解决此错误?

    1 回复  |  直到 7 年前
        1
  •  0
  •   matisetorm    7 年前

    没什么大不了的,只是没有调用正确的方法。

    尝试: nltk.metrics.scores.precision(reference, test)

    http://www.nltk.org/api/nltk.metrics.html

    ctrl+f“precision”将显示文档

    更正的代码: print('pos precision:', nltk.metrics.scores.precision(refsets['pos'],testsets['pos'])) print('pos recall:', nltk.metrics.scores.recall(refsets['pos'],testsets['pos']))