Python 如何从经过训练的支持向量机/LinearSVC中绘制重要特征?
代码的结尾是这样的——如果有一种方法可以自动绘制特性和它们的重要性,我如何绘制它们呢。 与此类似Python 如何从经过训练的支持向量机/LinearSVC中绘制重要特征?,python,scikit-learn,sentiment-analysis,Python,Scikit Learn,Sentiment Analysis,代码的结尾是这样的——如果有一种方法可以自动绘制特性和它们的重要性,我如何绘制它们呢。 与此类似 .... classifier_liblinear = svm.LinearSVC(loss='squared_hinge',max_iter=1000) classifier_liblinear.fit(train_vectors, train_labels) (来自) 我想出来了-至少要得到一份报告import numpy作为np def显示信息量最大的功能(矢量化器
....
classifier_liblinear = svm.LinearSVC(loss='squared_hinge',max_iter=1000)
classifier_liblinear.fit(train_vectors, train_labels)
(来自)
我想出来了-至少要得到一份报告
import numpy作为np def显示信息量最大的功能(矢量化器,clf,n=20):feature\u names=vectorizer.get\u feature\u names()coefs\u with_fns=sorted(zip(clf.coef\u[0],feature\u names])top=zip(coefs\u with_fns[:n],coefs\u with_fns[:-(n+1):-1]),顶部(coef_2,fn_2):打印“\t%.4f\t%-15s\t\t%.4f\t%-15s”%(coef_1,fn_1,coef_2,fn_2)显示信息量最大的特征(矢量器,分类器,75)