对于下面的代码,请告诉我如何使用我自己的数据集而不是 sklearn 的 20newsgroup 数据集。
我有 100 个聊天室 (.txt) 文件已被分类为正面和负面。
from sklearn.datasets import fetch_20newsgroups
import sklearn.feature_extraction.text as ext
categories = ['sci.space']
twenty_train = fetch_20newsgroups(subset='train',
categories=categories,
remove=('headers', 'footers', 'quotes'),
shuffle=True,
random_state=42)
count_chars = ext.CountVectorizer(analyzer='char_wb',
ngram_range=(3,3),
max_features=10).fit(twenty_train['data'])
count_words = ext.CountVectorizer(analyzer='word',
ngram_range=(3,3),
max_features=10,
stop_words='english').fit(twenty_train['data'])
X = count_chars.transform(twenty_train.data)
print (count_words.get_feature_names())
print ( X[1].todense())
感谢您的宝贵帮助!
最佳答案
将对 fetch-20newsgroups
的调用替换为代码
- 加载您的数据
- 预处理
关于python - 使用我的数据而不是 20 个新闻组进行情绪分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33028237/