簡體   English   中英

回歸與多維目標

[英]Regression with multi-dimensional targets

我正在使用scikit-learn做回歸,我的問題如下。 我需要對幾個參數(向量)進行回歸。 這適用於一些回歸方法,如ensemble.ExtraTreesRegressorensemble.RandomForestRegressor 實際上,可以給出矢量矢量作為目標以適合兩種上述回歸方法的模型( fit(X,y)方法)。

但是,當我嘗試使用ensemble.GradientBoostingRegressorensemble.AdaBoostRegressorlinear_model.SGDRegressor ,分類器無法擬合模型,因為它期望將1維值作為目標( fit(X,y)方法的y參數)。 這意味着,使用那些回歸方法,我一次只能估計一個參數。 這不適合我的問題,因為我需要花一些時間來估計大約20個參數。 另一方面,我真的想測試這些方法。

所以,我的問題是:有沒有人知道是否有適合模型的解決方案並估計ensemble.GradientBoostingRegressorensemble.AdaBoostRegressorlinear_model.SGDRegressor幾個參數?

我希望我已經足夠清楚......

我解釋你所擁有的是多元多元回歸的問題。

並非每個scikit-learn中的回歸方法都可以處理這類問題,您應該查閱每個問題的文檔以找出它。 特別是, SGDRegressorGradientBoostingRegressorAdaBoostRegressor目前都不支持這一點: fit(X, y)指定X:類似數組,shape = [n_samples,n_features]和y:array-like,shape = [n_samples]。

但是,您可以在scikit-learn中使用其他方法。 例如,線性模型:

from sklearn import linear_model
# multivariate input
X = [[0., 0.], [1., 1.], [2., 2.], [3., 3.]]
# univariate output
Y = [0., 1., 2., 3.]
# multivariate output
Z = [[0., 1.], [1., 2.], [2., 3.], [3., 4.]]

# ordinary least squares
clf = linear_model.LinearRegression()
# univariate
clf.fit(X, Y)
clf.predict ([[1, 0.]])
# multivariate
clf.fit(X, Z)
clf.predict ([[1, 0.]])

# Ridge
clf = linear_model.BayesianRidge()
# univariate
clf.fit(X, Y)
clf.predict ([[1, 0.]])
# multivariate
clf.fit(X, Z)
clf.predict ([[1, 0.]])

# Lasso
clf = linear_model.Lasso()
# univariate
clf.fit(X, Y)
clf.predict ([[1, 0.]])
# multivariate
clf.fit(X, Z)
clf.predict ([[1, 0.]])

如前所述,只有一些模型支持多變量輸出。 如果要使用其他一個,可以使用新類來並行化多變量輸出的回歸量: MultiOutputRegressor

你可以像這樣使用它:

from sklearn.datasets import load_linnerud
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.multioutput import MultiOutputRegressor

linnerud = load_linnerud()

X = linnerud.data
Y = linnerud.target

# to set number of jobs to the number of cores, use n_jobs=-1
MultiOutputRegressor(GradientBoostingRegressor(), n_jobs=-1).fit(X, Y)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM