通过CountVectorizer和chi2特征提取,进行文本分类,准确率只有0.34正常吗

代码如下:

#encoding=utf-8

from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
from sklearn.datasets import fetch_20newsgroups
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
from sklearn.svm import  SVC
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import accuracy_score,make_scorer
from sklearn.metrics import classification_report,accuracy_score
import numpy as n

categories = ['alt.atheism','talk.religion.misc','comp.graphics','sci.space']
data_train = fetch_20newsgroups(subset='train',categories=categories)
data_test = fetch_20newsgroups(subset='test',categories=categories)

count = CountVectorizer(stop_words='english',min_df=2)
train_feature = count.fit_transform(data_train.data)
print train_feature.toarray()
chi = SelectKBest(chi2,k=500)
train = chi.fit_transform(train_feature,data_train.target)
test_feature = count.fit_transform(data_test.data)
test = chi.fit_transform(test_feature,data_test.target)
# clf = MultinomialNB()
# classifier = clf.fit(train,data_train.target)
# test_accuracy = classifier.score(test,data_test.target)
# print test_accuracy

svc = SVC()
param_grid = {'kernel':('linear','poly'),'C':[0.1,1]}
grid_search = GridSearchCV(svc,param_grid=param_grid,cv=5,scoring=make_scorer(accuracy_score))
grid_search.fit(train,data_train.target)
y = grid_search.predict(test)
print grid_search.best_estimator_
print 'accuracy',accuracy_score(data_test.target,y)
print classification_report(data_test.target,y)

结果:
accuracy 0.34885439763488546
precision recall f1-score support

0 0.34 0.39 0.36 319
1 0.42 0.43 0.43 389
2 0.36 0.33 0.34 394
3 0.22 0.20 0.21 251

micro avg 0.35 0.35 0.35 1353
macro avg 0.34 0.34 0.34 1353
weighted avg 0.35 0.35 0.35 1353

求大佬指导一下 哪有问题吗

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐