Python - 使用朴素贝叶斯的 SelectFromModel

Python - SelectFromModel with Naive-Bayes

我正在使用 SelectFromModel in combination with MultinomialNB 在文本 class 化任务中进行特征选择。

SelectFromModel(estimator=MultinomialNB(alpha=1.0))

SelectFromModel 通过计算确定特征的重要性:

importances = np.linalg.norm(estimator.coef_, axis=0,ord=norm_order)

但这不是和我想要的完全相反吗,因为频率高的特征会导致绝对值低?

已经有多个很好回答的问题来确定给定特定特征的重要性class,但不是一般的特征重要性。

有没有一种方法可以结合 NB 使用 SelectFromModel 来确定特征重要性,或者是否有其他方法更适合此任务?

有一个函数称为带交叉验证的递归特征消除,也称为 RFECV in sklearn. It tries to rank the features according to their importance recursively and performs cross-validation to get the best number of features with the estimator specified. You can look at the example here 以获取更多信息。

我不确定为什么 selectFromModel 不能使用 NaiveBayes。如果我发现任何与之相关的内容,我将更新此答案。同时,您可以查看 RFECV 是否适合您的需求。