需要帮助解决错误 NameError: name 'countVectorizer' is not defined in PyCharm
我正在尝试从此源https://github.com/chdoig/pytexas2015-ml执行 FEATURE EXTRACTION 代码
文件名:1-Feature_extraction.ipynb
import numpy as np
import pandas as pd
train_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 plt
import seaborn as sns
train_data['review_len'] = train_data.review.apply(len)
len_pl = plt.hist(train_data.review_len.values)
plt.show(len_pl)
#describe negative reviews
print(train_data[train_data.sentiment==0].describe())
print(train_data[train_data.sentiment==1].describe())
#inspecting outliers
print(train_data[train_data.review_len==52].review.all())
print(train_data[train_data.review_len==13708].review.all())
#word exrtaction
from sklearn.feature_extraction.text import CountVectorizer
vocab = ['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 结束
精慕HU
相关分类