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

问题描述 投票:5回答:1

我正在尝试为我的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是一个数据框,其中包含我的每个功能的二进制列。

python scikit-learn classification feature-selection naivebayes
1个回答
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库中的高斯朴素贝叶斯方法获得班级的重要功能。

© www.soinside.com 2019 - 2024. All rights reserved.