sklearn.isotonic.IsotonicRegression?
閱讀更多內容用戶指南.
新版本0.13。
參數 | 說明 |
---|---|
y_min | float, default=None 最低預測值的下限(最小值可能更高)。如果沒有設置,默認為-inf。 |
y_max | float, default=None 最高預測值的上限(最大值可能仍然較低)。如果沒有設置,默認為+inf。 |
increasing | bool or ‘auto’, default=True 確定預測是否應限制為隨X增加或減少。“auto”將根據Spearman相關估計的符號來決定。 |
out_of_bounds | out_of_bounds:str, default=”nan” Out_Of_Bound參數如何處理訓練域之外的X值。當設置為“NaN”時,預測將為NaN。當設置為“clip”時,預測將被設置為與最近的訓練間隔終點相對應的值。當設置為“raise”時,將引發ValueError。 |
屬性 | 說明 |
---|---|
X_min_ | float 左界輸入數組X_的最小值。 |
X_max_ | float 右界輸入數組X_的最大值。 |
f_ | function 包含輸入域X的逐步插值函數。 |
increasing_ | bool 用于increasing的推斷值。 |
注
領帶是1977年用Leeuw的第二方法打破的。
參考文獻
1 Isotonic Median Regression: A Linear Programming Approach Nilotpal Chakravarti Mathematics of Operations Research Vol. 14, No. 2 (May, 1989), pp. 303-308
2 Isotone Optimization in R : Pool-Adjacent-Violators Algorithm (PAVA) and Active Set Methods Leeuw, Hornik, Mair Journal of Statistical Software 2009
3 Correctness of Kruskal’s algorithms for monotone regression with ties Leeuw, Psychometrica, 1977
實例
>>> from sklearn.datasets import make_regression
>>> from sklearn.isotonic import IsotonicRegression
>>> X, y = make_regression(n_samples=10, n_features=1, random_state=41)
>>> iso_reg = IsotonicRegression().fit(X.flatten(), y)
>>> iso_reg.predict([.1, .2])
array([1.8628..., 3.7256...])
方法
方法 | 說明 |
---|---|
fit (self, X, y[, sample_weight]) |
以X,y作為訓練數據對模型進行擬合。 |
fit_transform (self, X[, y]) |
適合數據,然后對其進行轉換。 |
get_params (self[, deep]) |
獲取此估計器的參數。 |
predict (self, T) |
用線性插值預測新數據。 |
score (self, X, y[, sample_weight]) |
返回預測的決定系數R^2。 |
set_params (self, **params) |
設置此估計器的參數。 |
transform (self, T) |
用線性插值變換新數據 |
__init__(self, *, y_min=None, y_max=None, increasing=True, out_of_bounds='nan')
[源碼]
初始化self, 請參閱help(type(self))以獲得準確的說明
fit(self, X, y, sample_weight=None)
[源碼]
以X,y作為訓練數據對模型進行擬合。
參數 | 說明 |
---|---|
X | array-like of shape (n_samples,) 培訓數據。 |
y | array-like of shape (n_samples,) 訓練目標。 |
sample_weight | array-like of shape (n_samples,), default=None 權重。如果設置為“無”,則所有權重將設置為1(相同的權重)。 |
返回值 | 說明 |
---|---|
self | object 返回Self的實例。 |
注
因為轉換需要X來插值新的輸入數據,所以X被存儲以供將來使用。
fit_transform(self, X, y=None, fit_params)
擬合數據,然后對其進行轉換。
使用可選參數fit_params將轉換器擬合到X和y,并返回X的轉換版本。
參數 | 說明 |
---|---|
X | {array-like, sparse matrix, dataframe} of shape (n_samples, n_features) |
Y | ndarray of shape (n_samples,), default=None 目標值。 |
**fit_params | dict 其他擬合參數。 |
返回值 | 說明 |
---|---|
X_new | ndarray array of shape (n_samples, n_features_new) 變換數組 |
get_params(self, deep=True)
[源碼]
獲取此估計量的參數。
參數 | 說明 |
---|---|
deep | bool, default=True 如果為True,則將返回此估計器的參數和包含的子對象,這些子對象是估計量。 |
返回值 | 說明 |
---|---|
params | mapping of string to any 映射到其值的參數名稱。 |
predict(self, T)
[源碼]
用線性插值預測新數據。
參數 | 說明 |
---|---|
T | array-like of shape (n_samples,) 要轉換的數據。 |
返回值 | 說明 |
---|---|
Y_pred | ndarray of shape (n_samples,) 轉換數據。 |
score(self, X, y, sample_weight=None)
[源碼]
返回預測的決定系數R^2。
系數R^2定義為(1-u/v),其中u是平方的殘差和((y_true-y_pred)2).sum(),v是平方和總和((y_true-y_true.means())2).sum()。最高得分可能為1.0,也可能為負(因為該模型可能會更差)。如果常量模型總是預測y的期望值,而不考慮輸入特征,R^2則會得到分數0.0。
參數 | 說明 |
---|---|
X | array-like of shape (n_samples, n_features) 測試樣本。對于某些估計量,這可能是一個預先計算的核矩陣或一個泛型對象的列表,即form=(n_sames,n_sames_擬合),其中n_sames_擬合是用于擬合估計器的樣本數。 |
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,預測(X)WRT.Y. |
注
在回歸器上調用分數時使用的R2分數使用版本0.23中的multioutput=‘CONFORMAL_Average’,以與默認值R2_SCORE保持一致。這會影響所有多輸出回歸變量的評分方法(MultiOutputRegressor除外)。
set_params(self, params)
[源碼]
設置此估計量的參數。
該方法適用于簡單估計量以及嵌套對象(例如pipelines)。后者具有形式的參數。<component>__<parameter>
這樣就可以更新嵌套對象的每個組件。
參數 | 說明 |
---|---|
params | dict 估計參數 |
返回值 | 說明 |
---|---|
self | object 估計實例 |
transform(self, T)
[源碼]
用線性插值變換新數據
參數 | 說明 |
---|---|
T | array-like of shape (n_samples,) 要轉換的數據。 |
返回值 | 說明 |
---|---|
y_pred | ndarray of shape (n_samples,) 轉換數據 |