2016-08-13 26 views
1

以下のコードでは以下のエラーが発生しますが、なぜ私のパラメータが無効であるのかわかりません。 SelectFromModelは、フィットおよび変換機能を備えているため、パイプラインで有効な入力です。sklearnのパイプラインでこのパラメータが無効なのはなぜですか?

ValueError: Invalid parameter sfm_threshold for estimator Pipeline. 
Check the list of available parameters with 
`estimator.get_params().keys()` 

from sklearn.preprocessing import PolynomialFeatures, StandardScaler 
from sklearn.linear_model import LassoCV, LinearRegression 
from sklearn.feature_selection import SelectFromModel 
from sklearn.pipeline import Pipeline 

poly = PolynomialFeatures() 
std = StandardScaler() 
ls = LassoCV(cv=10) 
sfm = SelectFromModel(estimator=ls) 
lr = LinearRegression() 

pipe_lr = Pipeline([('poly', poly), 
        ('std', std), 
        ('sfm', sfm), 
        ('lr', lr)]) 

param_range_degree = [2, 3] 
param_range_threshold = [0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5] 

param_grid_lr = [{'poly__degree': param_range_degree, 
        'sfm__threshold': param_range_threshold}] 

私はpipe_lr.get_params().keys()を実行すると、私は実際にはない以下の出力を、得るあるように私は正確にコピーして貼り付けsfm__thresholdが含まれます。

['std__with_mean', 
'sfm__estimator__precompute', 
'lr__n_jobs', 
'sfm__prefit', 
'poly', 
'sfm__threshold', 
'sfm__estimator__cv', 
'sfm__estimator__max_iter', 
'sfm__estimator__positive', 
'sfm__estimator__n_alphas', 
'std__with_std', 
'sfm__estimator__random_state', 
'std__copy', 
'lr__normalize', 
'sfm__estimator__copy_X', 
'lr', 
'sfm__estimator__n_jobs', 
'poly__interaction_only', 
'sfm__estimator__fit_intercept', 
'sfm__estimator__tol', 
'sfm__estimator', 
'sfm__estimator__verbose', 
'sfm', 
'sfm__estimator__normalize', 
'std', 
'sfm__estimator__selection', 
'poly__degree', 
'lr__copy_X', 
'sfm__estimator__alphas', 
'lr__fit_intercept', 
'steps', 
'poly__include_bias', 
'sfm__estimator__eps'] 
+0

問題の[最小、完全、および検証可能な例](// stackoverflow.com/help/mcve)*を教えてください。 –

+0

括弧を関数に代入すると、代入を介して渡されるインスタンスの型は、関数not type関数の戻り値の型になります。私の推測では、パイプラインは、非関数を渡すパラメータとして関数を取ろうとしています。 – kpie

+2

あなたのコードを実行中にエラーはありません。あなたはPython 2または3を使用していますか? – acknowledge

答えて

4

これは、あなたがsfm_thresholdを渡し、あなたがsfm__thresholdダブルアンダースコアに気づく)する必要があり、単純な入力ミスです。少なくともこれは最初のエラーが示すものです。

関連する問題