对于下面的代码,请告诉我如何使用我自己的数据集,而不是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())
谢谢你的宝贵帮助!在