Python sklearn - 如何计算 p 值 [英] Python sklearn - how to calculate p-values
本文介绍了Python sklearn - 如何计算 p 值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能是一个简单的问题,但我正在尝试使用用于分类问题的分类器或用于回归的回归器来计算我的特征的 p 值.有人可以建议每种情况的最佳方法是什么并提供示例代码吗?我只想查看每个特征的 p 值,而不是像文档中解释的那样保留 k 个最佳/特征百分比等.
谢谢
解决方案
直接对 X, y
进行显着性检验即可.使用 20news 和 chi2
的示例:
This is probably a simple question but I am trying to calculate the p-values for my features either using classifiers for a classification problem or regressors for regression. Could someone suggest what is the best method for each case and provide sample code? I want to just see the p-value for each feature rather than keep the k best / percentile of features etc as explained in the documentation.
Thank you
解决方案
Just run the significance test on X, y
directly. Example using 20news and chi2
:
>>> from sklearn.datasets import fetch_20newsgroups_vectorized
>>> from sklearn.feature_selection import chi2
>>> data = fetch_20newsgroups_vectorized()
>>> X, y = data.data, data.target
>>> scores, pvalues = chi2(X, y)
>>> pvalues
array([ 4.10171798e-17, 4.34003018e-01, 9.99999996e-01, ...,
9.99999995e-01, 9.99999869e-01, 9.99981414e-01])
这篇关于Python sklearn - 如何计算 p 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文