Getting NameError: name 'countVectorizer' is not defined in Pycharm
Getting NameError: name 'countVectorizer' is not defined in Pycharm
需要有关错误的帮助
NameError:名称 'countVectorizer' 未在 PyCharm
中定义
我正在尝试从此源执行特征提取代码
https://github.com/chdoig/pytexas2015-ml
文件名: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)
Error/Warning:
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;请参阅模块的文档以了解其他用途
进口进出口
追溯(最近一次通话):
文件 "C:/Users/hi/PycharmProjects/Practice2/P1.py",第 32 行,位于
simple_vectorizer = countVectorizer(词汇=词汇)
NameError:名称 'countVectorizer' 未定义
进程已完成,退出代码为 1
您正在导入 CountVectorizer 但引用 countVectorizer.
需要有关错误的帮助 NameError:名称 'countVectorizer' 未在 PyCharm
中定义我正在尝试从此源执行特征提取代码 https://github.com/chdoig/pytexas2015-ml
文件名: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)
Error/Warning: 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;请参阅模块的文档以了解其他用途 进口进出口 追溯(最近一次通话): 文件 "C:/Users/hi/PycharmProjects/Practice2/P1.py",第 32 行,位于 simple_vectorizer = countVectorizer(词汇=词汇) NameError:名称 'countVectorizer' 未定义
进程已完成,退出代码为 1
您正在导入 CountVectorizer 但引用 countVectorizer.