モデルがパイプラインに埋め込まれているときにscikit learnのサポートベクター回帰モデル(SVR)の係数にアクセスするのに問題があります。グリッド検索などがあります。 次の例を考えてみましょう:グリッド検索(GridSearchCV)とパイプラインを使用したサポートベクトル回帰(SVR)の係数Scikit Learn
from sklearn.datasets import load_iris
import numpy as np
from sklearn.grid_search import GridSearchCV
from sklearn.svm import SVR
from sklearn.feature_selection import SelectKBest
from sklearn.pipeline import Pipeline
iris = load_iris()
X_train = iris.data
y_train = iris.target
clf = SVR(kernel='linear')
select = SelectKBest(k=2)
steps = [('feature_selection', select), ('svr', clf)]
pipeline = Pipeline(steps)
grid = GridSearchCV(pipeline, param_grid={"svr__C":[10,10,100],"svr__gamma": np.logspace(-2, 2)})
grid.fit(X_train, y_train)
これは正常に動作するようですが、私は最高のフィッティングモデルの係数
grid.best_estimator_.coef_
にアクセスしようとすると、エラーメッセージが出ます:はAttributeError:「パイプライン」オブジェクトを'coef_'属性はありません。
私はまた、パイプラインの個々のステップアクセスしようとしました:
pipeline.named_steps['svr']
をそこ係数を見つけることができませんでした。ただ、同じ問題に遭遇することが起こった