为了账号安全,请及时绑定邮箱和手机立即绑定

获取 NameError:名称“countVectorizer”未在 Pycharm 中定义

获取 NameError:名称“countVectorizer”未在 Pycharm 中定义

慕侠2389804 2021-06-27 16:35:35
需要帮助解决错误 NameError: name 'countVectorizer' is not defined in PyCharm我正在尝试从此源https://github.com/chdoig/pytexas2015-ml执行 FEATURE EXTRACTION 代码文件名:1-Feature_extraction.ipynbimport numpy as npimport pandas as pdtrain_data = pd.read_csv('labeledTrainData.tsv',sep='\t')print(train_data)print(train_data.iloc[1].review)test_data = pd.read_csv('testData.tsv',sep = '\t')print(test_data)import matplotlib.pyplot as pltimport seaborn as snstrain_data['review_len'] = train_data.review.apply(len)len_pl = plt.hist(train_data.review_len.values)plt.show(len_pl)#describe negative reviewsprint(train_data[train_data.sentiment==0].describe())print(train_data[train_data.sentiment==1].describe())#inspecting outliersprint(train_data[train_data.review_len==52].review.all())print(train_data[train_data.review_len==13708].review.all())#word exrtactionfrom sklearn.feature_extraction.text import CountVectorizervocab = ['awesome', 'terrible']simple_vectorizer = countVectorizer(vocabulary=vocab)bow = simple_vectorizer.fit_transform(train_data.review).todense()print(bow)错误/警告: C:\Users\hi\PycharmProjects\Practice2\venv\Scripts\python.exe C:/Users/hi/PycharmProjects/Practice2/P1.py C:\Users\hi\PycharmProjects\Practice2\venv\lib \site-packages\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py:47: DeprecationWarning: 不推荐使用 imp 模块以支持 importlib;请参阅模块文档以了解替代用途 import imp Traceback(最近一次调用最后一次):文件“C:/Users/hi/PycharmProjects/Practice2/P1.py”,第 32 行,在 simple_vectorizer = countVectorizer(vocabulary=vocab) NameError: name 'countVectorizer' 未定义进程以退出代码 1 结束
查看完整描述

1 回答

?
精慕HU

TA贡献1845条经验 获得超8个赞

您正在导入CountVectorizer但引用的是countVectorizer


查看完整回答
反对 回复 2021-07-06
  • 1 回答
  • 0 关注
  • 1040 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信