sklearn.multioutput.MultiOutputRegressor?

class sklearn.multioutput.MultiOutputRegressor(estimator, *, n_jobs=None)

[源碼]

多目標回歸

該策略包括為每個目標安裝一個回歸器。這是擴展本來不支持多目標回歸的回歸變量的簡單策略。

版本0.18中的新功能。

參數 說明
estimator estimator object
實現擬合預測的估計對象。
n_jobs int or None, optional (default=None)
為并行運行的作業數fitNone除非在joblib.parallel_backend上下文中,否則表示1 。 -1表示使用所有處理器。有關 更多詳細信息,請參見詞匯表
當各個估算器快速訓練或預測使用n_jobs>1時,由于生成過程的開銷而導致性能降低。
v0.20版中的更改:n_jobs默認從1更改為None
屬性 說明
estimators_ list of n_output estimators
用于預測的估計量。

實例

>>> import numpy as np
>>> from sklearn.datasets import load_linnerud
>>> from sklearn.multioutput import MultiOutputRegressor
>>> from sklearn.linear_model import Ridge
>>> X, y = load_linnerud(return_X_y=True)
>>> clf = MultiOutputRegressor(Ridge(random_state=123)).fit(X, y)
>>> clf.predict(X[[0]])
array([[176..., 35..., 57...]])
方法 說明
fit(X, y[, sample_weight]) 使模型擬合數據。
get_params([deep]) 獲取此估計量的參數。
partial_fit(X, y[, sample_weight]) 使模型逐漸擬合數據。
predict(X) 使用模型預測多輸出變量
score(X, y[, sample_weight]) 返回預測的確定系數R ^ 2。
set_params(**params) 設置此估算量的參數。
__init__(estimator, *, n_jobs=None)

[源碼]

初始化self, 請參閱help(type(self))以獲得準確的說明。

fit(X, y, sample_weight=None, **fit_params)

[源碼]

使模型擬合數據。為每個輸出變量擬合一個單獨的模型。

參數 說明
X (sparse) array-like, shape (n_samples, n_features)
數據。
y (sparse) array-like, shape (n_samples, n_outputs)
多輸出目標。指標矩陣可打開多標簽估計。
sample_weight array-like of shape (n_samples,), default=None
樣本權重。如果為None,則對樣本進行平均加權。僅當基礎回歸變量支持樣本權重時才支持。
**fit_params dict of string -> object
參數傳遞給estimator.fit每個步驟的方法。
返回值 說明
self object
get_params(deep=True)

[源碼]

獲取此估計量的參數。

參數 說明
deep bool, default=True
如果為True,則將返回此估算器和作為估算器的所包含子對象的參數。
返回值 說明
params mapping of string to any
參數名稱映射到其值。
partial_fit(X, y, sample_weight=None)

[源碼]

使模型逐漸擬合數據。為每個輸出變量擬合一個單獨的模型。

參數 說明
X (sparse) array-like, shape (n_samples, n_features)
數據。
y (sparse) array-like, shape (n_samples, n_outputs)
多輸出目標。
sample_weight array-like of shape (n_samples,), default=None
樣本權重。如果為None,則對樣本進行平均加權。僅當基礎回歸變量支持樣本權重時才支持。
返回值 說明
self object
predict(X)

[源碼]

使用模型預測多輸出變量

? 針對每個目標變量進行訓練。

參數 說明
X (sparse) array-like, shape (n_samples, n_features)
數據。
返回值 說明
y (sparse) array-like, shape (n_samples, n_outputs)
跨多個預測變量預測的多輸出目標。注意:為每個預測變量生成單獨的模型。
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的期望值的恒定模型將獲得0.0的R ^ 2分數。

參數 說明
X array-like of shape (n_samples, n_features)
測試樣本。對于某些估計量,這可能是一個預先計算的核矩陣或泛型對象列表,shape=(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
self.predict(X) wrt. y.的R^2

調用score回歸器時使用的R2得分multioutput='uniform_average'從0.23版開始使用 ,r2_score已與默認值保持一致。這會影響score所有多輸出回歸變量的方法(除外 MultiOutputRegressor)。

set_params(**params)

[源碼]

設置此估算器的參數。

該方法適用于簡單的估計器以及嵌套對象(例如 pipelines)。后者具有形式的參數, <component>__<parameter>以便可以更新嵌套對象的每個組件。

參數 說明
**params dict
估算量參數。
返回值 說明
self object
估算量實例。

sklearn.multioutput.MultiOutputRegressor使用實例?