特徵選擇過濾器 - f_regression(單變量線性迴歸測試)


官方網站:sklearn.feature_selection.f_regression

sklearn.feature_selection.f_regression(X,y,center = True

數學原理

單變量線性迴歸測試。

用於測試許多回歸變量各自的效果的線性模型。這是要在特徵選擇過程中使用的評分功能,而不是獨立式特徵選擇過程。

分兩個步驟完成:

  1. 計算每個迴歸變量與目標之間的相關性,即(((X [:, i]-mean(X [:, i]))(y-mean_y))/(std(X [:, i] ) std(y))。

  2. 將其轉換爲F分數,然後轉換爲p值。

參數說明

Parameters
----------
X:{array-like, sparse matrix} shape = (n_samples, n_features)
   將按順序測試的一組迴歸函數。
   The set of regressors that will be tested sequentially.

y:array of shape(n_samples).
   數據矩陣
   The data matrix

center:True, bool,
		如果爲true,則X和y將居中。
		If true, X and y will be centered.

Returns
-------
F:array, shape=(n_features,)
   特徵的F值。	
   F values of features.

pval:array, shape=(n_features,)
	  F得分的p值。
      p-values of F-scores.

示例

數據

  • 樣本數:1000
  • 特徵數:3(3維數據)
  • 重要特徵:1
from sklearn.datasets import make_regression

X,y = make_regression(n_samples=1000, n_features=3, n_informative=1, noise=100, random_state=9527)

使用 f_regression 計算特徵的相關性

from sklearn import feature_selection as FS

fv, pv = FS.f_regression(X, y)

特徵的 F-value

print(fv)
>>>[1.67054044e-01 8.04573104e+02 1.55086141e+00]

F-value 的 p-value

print(pv)
>>>[6.82831040e-001 2.83453762e-130 2.13300627e-001]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章