.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/feature_selection/plot_f_test_vs_mi.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. or to run this example in your browser via Binder .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_feature_selection_plot_f_test_vs_mi.py: =========================================== 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为无关特征。 .. GENERATED FROM PYTHON SOURCE LINES 17-42 .. image-sg:: /auto_examples/feature_selection/images/sphx_glr_plot_f_test_vs_mi_001.png :alt: F-test=1.00, MI=0.36, F-test=0.28, MI=1.00, F-test=0.00, MI=0.00 :srcset: /auto_examples/feature_selection/images/sphx_glr_plot_f_test_vs_mi_001.png :class: sphx-glr-single-img .. code-block:: Python 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() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.138 seconds) .. _sphx_glr_download_auto_examples_feature_selection_plot_f_test_vs_mi.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/scikit-learn/scikit-learn/main?urlpath=lab/tree/notebooks/auto_examples/feature_selection/plot_f_test_vs_mi.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_f_test_vs_mi.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_f_test_vs_mi.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_f_test_vs_mi.zip ` .. include:: plot_f_test_vs_mi.recommendations .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_