sklearn.linear_model.OrthogonalMatchingPursuit?
class sklearn.linear_model.OrthogonalMatchingPursuit(*, n_nonzero_coefs=None, tol=None, fit_intercept=True, normalize=True, precompute='auto')
正交匹配追蹤模型(OMP)。
在用戶指南中閱讀更多內容。
參數 | 說明 |
---|---|
n_nonzero_coefs | int, optional 解決方案中所需的非零項數。如果為None(默認),則此值設置為n_features的10%。 |
tol | float, optional 殘數的最大范數。如果不是None,則覆蓋n_nonzero_coefs。 |
fit_intercept | boolean, optional 是否計算該模型的截距。如果設置為false,則在計算中將不使用截距(即,數據應是中心化的)。 |
normalize | boolean, optional, default Truefit_intercept 設置為False 時,將忽略此參數。如果為True,則在回歸之前通過減去均值并除以l2-范數來對回歸變量X進行歸一化。如果你希望標準化,請先使用 sklearn.preprocessing.StandardScaler ,然后調用fit 估算器并設置normalize=False 。 |
precompute | {True, False, ‘auto’}, default ‘auto’ 是否使用預先計算的Gram和Xy矩陣來加快計算速度。當n_targets或 n_samples非常大時提高性能。請注意,如果已經有這樣的矩陣,則可以將它們直接傳遞給fit方法。 |
屬性 | 說明 |
---|---|
coef_ | array, shape (n_features,) or (n_targets, n_features) 參數向量(公式中的w) |
intercept_ | float or array, shape (n_targets,) 目標函數中的截距。 |
n_iter_ | int or array-like 每個目標上的活動特征數量。 |
另見
orthogonal_mp
orthogonal_mp_gram
lars_path
Lars
LassoLars
decomposition.sparse_encode
OrthogonalMatchingPursuitCV
注
正交匹配追蹤是在G. Mallat,Z. Zhang中引入的,《時頻字典的匹配追蹤》,IEEE Transactions on Signal Processing,Vol。41,No.12(1993年12月),第3397-3415頁。(http://blanche.polytechnique.fr/~mallat/papiers/MallatPursuit93.pdf)
此實現基于R.Rubinstein,M.Zibulevsky和M.Elad的《使用批正交匹配追蹤技術報告有效實現K-SVD算法》,CS Technion,2008年4月 .https://www.cs。 technion.ac.il/~ronrubin/Publications/KSVD-OMP-v2.pdf
示例
>>> from sklearn.linear_model import OrthogonalMatchingPursuit
>>> from sklearn.datasets import make_regression
>>> X, y = make_regression(noise=4, random_state=0)
>>> reg = OrthogonalMatchingPursuit().fit(X, y)
>>> reg.score(X, y)
0.9991...
>>> reg.predict(X[:1,])
array([-78.3854...])
方法
方法 | 說明 |
---|---|
fit (X, y[, copy_X]) |
使用X,y作為訓練數據擬合模型。 |
get_params ([deep]) |
獲取此估計量的參數。 |
predict (X) |
使用線性模型進行預測。 |
score (X, y[, sample_weight]) |
返回預測的確定系數R ^ 2。 |
set_params (**params) |
設置此估算器的參數。 |
__init__(standard ='aic',*,fit_intercept = True,verbose = False,normalize = True,precompute ='auto',max_iter = 500,eps = 2.220446049250313e-16,copy_X = True,positive = False )
[源碼]
初始化self, 請參閱help(type(self))以獲得準確的說明。
fit(X, y, copy_X=None)
[源碼]
使用X,y作為訓練數據擬合模型。
參數 | 說明 |
---|---|
X | array-like of shape (n_samples, n_features) 訓練數據。 |
y | array-like of shape (n_samples,) 目標值。如有必要,將強制轉換為X的數據類型 |
copy_X | bool, default=None 如果設置了此參數,它將覆蓋實例創建時選擇的copy_X。如果True ,X將被復制;否則X可能會被覆蓋。 |
返回值 | 說明 |
---|---|
self | object 返回估計器實例 |
get_params(deep=True)
[源碼]
獲取此估計量的參數。
參數 | 說明 |
---|---|
deep | bool, default=True 如果為True,則將返回此估算器和所包含子對象的參數。 |
返回值 | 說明 |
---|---|
params | mapping of string to any 參數名稱映射到其值。 |
predict(X)
[源碼]
使用線性模型進行預測。
參數 | 說明 |
---|---|
X | array_like or sparse matrix, shape (n_samples, n_features) 樣本數據 |
返回值 | 說明 |
---|---|
C | array, shape (n_samples,) 返回預測值。 |
score(X, y, sample_weight=None)
[源碼]
返回預測的確定系數R ^ 2。
系數R ^ 2定義為(1- u / v),其中u是殘差平方和((y_true-y_pred)** 2).sum(),而v是總平方和((y_true- y_true.mean())** 2).sum()。可能的最高得分為1.0,并且也可能為負(因為該模型可能會更差)。一個常數模型總是預測y的期望值,而不考慮輸入特征,得到的R^2得分為0.0。
參數 | 說明 |
---|---|
X | array-like of shape (n_samples, n_features) 測試樣本。對于某些估計量,這可以是預先計算的內核矩陣或通用對象列表,形狀為(n_samples,n_samples_fitted),其中n_samples_fitted是用于擬合估計器的樣本數。 |
y | array-like of shape (n_samples,) or (n_samples, n_outputs) X的真實值。 |
sample_weight | array-like of shape (n_samples,), default=None 樣本權重。 |
返回值 | 說明 |
---|---|
score | float 預測值與真實值的R^2。 |
注
調用回歸器中的score
時使用的R2分數,multioutput='uniform_average'
從0.23版開始使用 ,與r2_score
默認值保持一致。這會影響多輸出回歸的score
方法( MultiOutputRegressor
除外)。
set_params(**params)
[源碼]
設置此估計器的參數。
該方法適用于簡單的估計器以及嵌套對象(例如管道)。后者具有形式為 <component>__<parameter>
的參數,這樣就可以更新嵌套對象的每個組件。
參數 | 說明 |
---|---|
**params | dict 估計器參數。 |
返回值 | 說明 |
---|---|
self | object 估計器實例。 |