Scikit learn 参数具有弹性值误差的交叉Val分数

Scikit learn 参数具有弹性值误差的交叉Val分数,scikit-learn,cross-validation,valueerror,Scikit Learn,Cross Validation,Valueerror,我试图使用cross\u val\u score()函数和嵌套交叉验证在python中实现一个简单的弹性网络回归,但它不允许我传递参数。它一直在为我的l1_比率声明一个无效参数的ValueError,我不明白为什么给定它在0和1之间 ValueError: Invalid parameter l1_ratio for estimator Pipeline(steps=[('preprocessor', ColumnTransformer(remainder='p

我试图使用
cross\u val\u score()
函数和嵌套交叉验证在python中实现一个简单的弹性网络回归,但它不允许我传递参数。它一直在为我的l1_比率声明一个无效参数的ValueError,我不明白为什么给定它在0和1之间

ValueError: Invalid parameter l1_ratio for estimator Pipeline(steps=[('preprocessor',
                 ColumnTransformer(remainder='passthrough',
                                   transformers=[('cat', OneHotEncoder(), [0]),
                                                 ('num', StandardScaler(),
                                                  slice(1, 37, None))])),
                ('model', ElasticNet(random_state=42))]).
Check the list of available parameters with `estimator.get_params().keys()`.
我的代码:

cv_outer=KFold(10, shuffle=True)
cv_inner=KFold(10, shuffle=True)
models_params = {
    'en': (LREN(random_state=42), # Elastic Net
        {'l1_ratio': [0,0.25,0.5,0.75,1]
         ,'alpha':[1e-2,1e-1,1,1e1]})
# My first column is Categorical, the other 36 are numerical
preprocessor = ColumnTransformer(
                    transformers=[
                        ('cat', OneHotEncoder(), [0])
                        ,('num', StandardScaler(), slice(1,37))
                    ]
                    ,remainder = 'passthrough')
# Store Results
average_scores = dict()
for name, (model, params) in models_params.items():
    mymodel = Pipeline(steps = [('preprocessor', preprocessor),
                                ('model', model)
                                ])
        # this object is a regressor that also happens to choose
        # its hyperparameters automatically using `inner_cv`
    optimize_hparams = GridSearchCV(
            estimator = mymodel, param_grid=params, n_jobs = -1,
            cv=cv_inner, scoring='neg_mean_absolute_error')
# estimate generalization error on the outer-fold splits of the data
    outer_folds_scores = cross_val_score(
        optimize_hparams,
        X, y, cv=cv_outer, scoring='neg_mean_absolute_error')

您可以尝试定义网格,例如:

models_params = {
        {'model__l1_ratio': [0,0.25,0.5,0.75,1],
         'model__alpha':[1e-2,1e-1,1,1e1]}
    }

啊,是的,我记得其他车型需要在其他地方这样做。小挫折。是的,你需要这样做,当你有很多步骤在你的管道