2017-10-24 12 views
3

파이프 라인을 사용하여 회귀 (차수 = 3)에 사용 된 다항식의 차수를 지정하는 간단한 회귀 작업을 수행하려고합니다. 그래서 정의파이프 라인을 사용하여 쿼리 포인트의 예측 분포의 표준 편차

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

그리고 피팅 :

pipe.fit(X_train, y_train) 

그리고 마지막으로 예측 비트

:

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의 파이프 라인 모듈의 버그했다. 최신 버전으로 수정되었습니다.

참조 :