猫史档案馆


求助()()()()()

用户:伴雪纷飞伴雪纷飞查看:9 回复:6 评论:9 创建时间:2021-10-23T20:26:59


[nltk_data] Error loading averaged_perceptron_tagger: <urlopen error
[nltk_data]     [Errno 11004] getaddrinfo failed>
[nltk_data] Error loading punkt: <urlopen error [Errno 11004]
[nltk_data]     getaddrinfo failed>
Traceback (most recent call last):
  File "C:\Users\admin\.wood\python_x喵\Lib\site-packages\nltk\corpus\util.py", line 84, in __load
    root = nltk.data.find(f"{self.subdir}/{zip_name}")
  File "C:\Users\admin\.wood\python_x喵\Lib\site-packages\nltk\data.py", line 583, in find
    raise LookupError(resource_not_found)
LookupError:
**********************************************************************
  Resource movie_reviews not found.
  Please use the NLTK Downloader to obtain the resource:

  >>> import nltk
  >>> nltk.download('movie_reviews')

  For more information see: https://www.nltk.org/data.html

  Attempted to load corpora/movie_reviews.zip/movie_reviews/

  Searched in:
    - 'C:\\Users\\admin/nltk_data'
    - 'C:\\Pyblock\\resources\\app\\Python-win喵\\nltk_data'
    - 'C:\\Pyblock\\resources\\app\\Python-win喵\\share\\nltk_data'
    - 'C:\\Pyblock\\resources\\app\\Python-win喵\\lib\\nltk_data'
    - 'C:\\Users\\admin\\AppData\\Roaming\\nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - '.\\corpora\\movie_reviews'
**********************************************************************


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\admin\Desktop\py项目本\lesson\电影评论\nltk_data\nltk_data\电影评论分析.py", line 10, in <module>
    positive_fileids = movie_reviews.fileids('pos')
  File "C:\Users\admin\.wood\python_x喵\Lib\site-packages\nltk\corpus\util.py", line 121, in __getattr__
    self.__load()
  File "C:\Users\admin\.wood\python_x喵\Lib\site-packages\nltk\corpus\util.py", line 86, in __load
    raise e
  File "C:\Users\admin\.wood\python_x喵\Lib\site-packages\nltk\corpus\util.py", line 81, in __load
    root = nltk.data.find(f"{self.subdir}/{self.__name}")
  File "C:\Users\admin\.wood\python_x喵\Lib\site-packages\nltk\data.py", line 583, in find
    raise LookupError(resource_not_found)
LookupError:
**********************************************************************
  Resource movie_reviews not found.
  Please use the NLTK Downloader to obtain the resource:

  >>> import nltk
  >>> nltk.download('movie_reviews')

  For more information see: https://www.nltk.org/data.html

  Attempted to load corpora/movie_reviews

  Searched in:
    - 'C:\\Users\\admin/nltk_data'
    - 'C:\\Pyblock\\resources\\app\\Python-win喵\\nltk_data'
    - 'C:\\Pyblock\\resources\\app\\Python-win喵\\share\\nltk_data'
    - 'C:\\Pyblock\\resources\\app\\Python-win喵\\lib\\nltk_data'
    - 'C:\\Users\\admin\\AppData\\Roaming\\nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - '.\\corpora\\movie_reviews'
**********************************************************************​
from nltk.classify import NaiveBayesClassifier
from nltk.corpus import movie_reviews
import nltk.classify.util
from nltk import data
nltk.download('averaged_perceptron_tagger')
nltk.download('punkt')
data.path.append('.\corpora\movie_reviews')

#加载评论
positive_fileids = movie_reviews.fileids('pos')
negative_fileids = movie_reviews.fileids('neg')

#提取特征
def extract_features(word_list):
    return dict([(word,True) for word in word_list])

features_positive=[]
for f in positive_fileids:
    word_list=movie_reviews.words(f)
    word_features=extract_features(word_list)
    features_positive.append((word_features,'Positive'))
features_negative=[]
for f in negative_fileids:
    word_list = movie_reviews.words(f)
    word_features = extract_features(word_list)
    features_negative.append((word_features, 'Negative'))

threshold_factor=0.8
threshold_positive=int(threshold_factor*len(features_positive))
threshold_negative = int(threshold_factor*len(features_negative))

words_train=features_positive[:threshold_positive]+\
features_negative[:threshold_negative]

words_test=features_positive[threshold_positive:]+\
features_negative[threshold_negative:]
print('\n测试数量:',len(words_train))
print('训练集数量:',len(words_test))

classifier=NaiveBayesClassifier.train(words_train)
print('分类准确性:',nltk.classify.accuracy(classifier,words_test))

 


回复

上一页1 页 / 共 1下一页
伴雪纷飞伴雪纷飞

搞分类器时遇到的bug

有人吗

点赞0


评论


SCS_user_bg63g3etzaSCS_user_bg63g3etza

print("hhhh")

点赞0


评论


lsk666666lsk666666

这就触及到我的知识盲区了,我就对ai这些东西一窍不通

点赞1


评论


Albert钟Albert钟

安装问题吧,重新安装nltk

点赞1


评论


Albert钟Albert钟

而且不要在海龟里运行((各种环境变量错误

点赞1


评论


伴雪纷飞伴雪纷飞

翻古贴(黑

这里还是碳基的遗址

点赞0


评论