【发布时间】:2019-04-29 14:05:57
【问题描述】:
我正在尝试为我的 GaussianNB 模型获取最重要的功能。来自How to get most informative features for scikit-learn classifiers? 或How to get most informative features for scikit-learn classifier for different class? 的代码仅在我使用 MultinomialNB 时有效。否则,我如何计算或检索两个类(Fault = 1 或 Fault = 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 是一个数据框,其中包含我的每个功能的二进制列。
【问题讨论】:
-
This accepted answer 讨论仅获取二进制分类案例的特征
-
这是我引用的例子:它只适用于伯努利或多项式,但不适用于高斯
-
您可以使用置换特征重要性:scikit-learn.org/stable/modules/permutation_importance.html,它与模型无关,会告诉您哪个特征是重要的。
标签: python scikit-learn classification feature-selection naivebayes