2017-10-24 4 views
3

パイプラインを使用して単純回帰タスクを実行して、回帰(次数= 3)に使用される多項式の次数を割り当てようとしています。パイプラインを使用したクエリポイントの予測分布の標準偏差

pipe.fit(X_train, y_train) 

そして最後に予測ビット:

pipe = make_pipeline(PolynomialFeatures(3), BayesianRidge()) 

そしてフィッティング:だから私は定義し、そのを予測するために

y_pred = pipe.predict(X_test) 

BayesianRidge()sklearnのはreturn_stdパラメータを持っていますメソッドは、Trueに設定すると、クエリポイントの予測分布の標準偏差を返します。

パイプラインを使ってこの標準偏差アレイを得ることができますか?

答えて

1

their github repositoryからscikit-learnの最新バージョンをインストールする必要があります。次に、partial from functoolsを使用するだけです。私はBayesian Ridge Regression docsで言及されたものに似た例を使用しました。

from sklearn import linear_model 
from sklearn.preprocessing import PolynomialFeatures 
from sklearn.pipeline import make_pipeline 
from functools import partial 

clf = linear_model.BayesianRidge() 

#Make the pipeline 
pipe = make_pipeline(PolynomialFeatures(3), clf) 

#Patch the predict function of the classifier using partial 
clf.predict = partial(clf.predict,return_std=True) 

#Fit the pipeline 
pipe.fit([[0,0], [1, 1], [2, 2]], [0, 1, 2]) 

#Retrieve the prediction and standard deviation 
y_pred, y_std = pipe.predict([[1,2]]) 
#Output : (array([ 1.547614]), array([ 0.25034696])) 

注:どうやらこれはdescribed hereとしてsklearnのパイプラインモジュールのバグでした。最新バージョンで修正されました。

参考:

関連する問題