【发布时间】:2019-06-04 03:37:21
【问题描述】:
我有一个朴素贝叶斯分类器,我使用 Pandas 数据框在 Python 中编写,现在我在 PySpark 中需要它。我的问题是我需要每列的特征重要性。查看 PySpark ML 文档时,我找不到任何信息。 documentation
有谁知道我是否可以使用 Naive Bayes Spark MLlib 获得特征重要性?
使用 Python 的代码如下。使用 .coef_
检索特征重要性df = df.fillna(0).toPandas()
X_df = df.drop(['NOT_OPEN', 'unique_id'], axis = 1)
X = X_df.values
Y = df['NOT_OPEN'].values.reshape(-1,1)
mnb = BernoulliNB(fit_prior=True)
y_pred = mnb.fit(X, Y).predict(X)
estimator = mnb.fit(X, Y)
# coef_: For a binary classification problems this is the log of the estimated probability of a feature given the positive class. It means that higher values mean more important features for the positive class.
feature_names = X_df.columns
coefs_with_fns = sorted(zip(estimator.coef_[0], feature_names))
【问题讨论】:
标签: apache-spark pyspark naivebayes apache-spark-ml