f_classif#

sklearn.feature_selection.f_classif(X, y)[source]#

计算所提供样本的 ANOVA F 值。

用户指南中阅读更多内容。

参数:
Xshape 为 (n_samples, n_features) 的 {array-like, sparse matrix}

将按顺序测试的回归量集。

yarray-like of shape (n_samples,)

目标向量。

返回:
f_statisticndarray of shape (n_features,)

每个特征的 F 统计量。

p_valuesndarray of shape (n_features,)

与 F 统计量相关的 P 值。

另请参阅

chi2

分类任务中非负特征的卡方统计量。

f_regression

回归任务中标签/特征之间的 F 值。

示例

>>> from sklearn.datasets import make_classification
>>> from sklearn.feature_selection import f_classif
>>> X, y = make_classification(
...     n_samples=100, n_features=10, n_informative=2, n_clusters_per_class=1,
...     shuffle=False, random_state=42
... )
>>> f_statistic, p_values = f_classif(X, y)
>>> f_statistic
array([2.21e+02, 7.02e-01, 1.70e+00, 9.31e-01,
       5.41e+00, 3.25e-01, 4.71e-02, 5.72e-01,
       7.54e-01, 8.90e-02])
>>> p_values
array([7.14e-27, 4.04e-01, 1.96e-01, 3.37e-01,
       2.21e-02, 5.70e-01, 8.29e-01, 4.51e-01,
       3.87e-01, 7.66e-01])