F检验与互信息的比较#

此示例说明了单变量F检验统计量和互信息之间的差异。

我们考虑3个特征x_1,x_2,x_3均匀分布在 [0, 1] ,目标取决于他们如下:

y = x_1 + sin(6 * pi * x_2)+ 0.1 * N(0,1),即第三个特征完全无关。

下面的代码绘制了y对单个x_i的依赖性以及单变量F测试统计量和互信息的标准化值。

由于F测试仅捕捉线性相关性,因此它将x_1评为最具区分性的特征。另一方面,互信息可以捕捉变量之间的任何类型的依赖性,并且它将x_2评为最具区分性的特征,这可能更符合我们对这个例子的直觉。两种方法都正确地将x_3标记为不相关。

F-test=1.00, MI=0.36, F-test=0.28, MI=1.00, F-test=0.00, MI=0.00
# Authors: The scikit-learn developers
# SPDX-License-Identifier: BSD-3-Clause

import matplotlib.pyplot as plt
import numpy as np

from sklearn.feature_selection import f_regression, mutual_info_regression

np.random.seed(0)
X = np.random.rand(1000, 3)
y = X[:, 0] + np.sin(6 * np.pi * X[:, 1]) + 0.1 * np.random.randn(1000)

f_test, _ = f_regression(X, y)
f_test /= np.max(f_test)

mi = mutual_info_regression(X, y)
mi /= np.max(mi)

plt.figure(figsize=(15, 5))
for i in range(3):
    plt.subplot(1, 3, i + 1)
    plt.scatter(X[:, i], y, edgecolor="black", s=20)
    plt.xlabel("$x_{}$".format(i + 1), fontsize=14)
    if i == 0:
        plt.ylabel("$y$", fontsize=14)
    plt.title("F-test={:.2f}, MI={:.2f}".format(f_test[i], mi[i]), fontsize=16)
plt.show()

Total running time of the script: (0分0.168秒)

相关实例

用排列测试分类分数的重要性

Test with permutations the significance of a classification score

集群绩效评估中的机会调整

Adjustment for chance in clustering performance evaluation

单变量特征选择

Univariate Feature Selection

网格搜索和连续减半的比较

Comparison between grid search and successive halving

Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io> _