最重要的特征高斯朴素贝叶斯分类器python sklearn

时间:2018-11-27 18:53:22

标签: python scikit-learn classification feature-selection naivebayes

我正在尝试为我的GaussianNB模型获得最重要的功能。仅当我使用MultinomialNB时,此处How to get most informative features for scikit-learn classifiers? 或此处How to get most informative features for scikit-learn classifier for different class?的代码才有效。否则,如何为我的两个类(故障= 1或故障= 0)中的每一个计算或检索最重要的特征? 我的代码是:(不适用于文本数据)

df = df.toPandas()

X = X_df.values
Y = df['FAULT'].values.reshape(-1,1)


gnb = GaussianNB() 
y_pred = gnb.fit(X, Y).predict(X)

print(confusion_matrix(Y, y_pred))
print(accuracy_score(Y, y_pred))

其中X_df是一个数据框,其中包含我的每个功能的二进制列。

1 个答案:

答案 0 :(得分:0)

这就是我试图了解高斯NB的重要功能的方法。 SKlearn高斯NB模型包含参数theta和sigma,它们是每个类每个特征的方差和均值(例如:如果是二进制分类问题,则model.sigma_将返回两个数组和每个类每个特征的均值)

neg = model.theta_[0].argsort()
print(np.take(count_vect.get_feature_names(), neg[:10]))

print('')

neg = model.sigma_[0].argsort()
print(np.take(count_vect.get_feature_names(), neg[:10]))

这就是我尝试使用scikit-learn库中的高斯朴素贝叶斯方法获取班级的重要功能的方法。