imblearn库:set_params报错Invalid parameter xxxx for estimator Pipeline

用imblearn库的pipline设置参数时,一直设一直报错。

# 设评估分数的空字典
fpr = dict()
tpr = dict()
roc_auc = dict()
# 设多个参数
ratio = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7]
C =     [3, 3, 3, 2, 2, 2, 2]
gamma = [.02, .009, .009, .005, .0008, .0009, .0007]
# 设管道
estimators = [('smt', SVMSMOTE(random_state=42)), 
              ('clf', SVC(probability=True, random_state=42))]
pipe = Pipeline(estimators)

# 将多个参数写入模型中
for i, r, c, g in zip(list(range(7)), ratio, C, gamma):

    pipe.set_params(smt_sampling_strategy = r, clf_C = c, clf_gamma = g)
    probas_ = pipe.fit(X_train_scaled, y_train).predict_proba(X_holdout_scaled)
    fpr[i], tpr[i], _ = roc_curve(y_holdout, probas_[:,1])
    roc_auc[i] = auc(fpr[i], tpr[i])

报错,返回
ValueError: Invalid parameter smt_sampling_strategy for estimator Pipeline(memory=None,
steps=[(‘clf’,
SVC(C=3, break_ties=False, cache_size=200, class_weight=None,
coef0=0.0, decision_function_shape=‘ovr’, degree=3,
gamma=0.009, kernel=‘rbf’, max_iter=-1, probability=True,
random_state=42, shrinking=True, tol=0.001,
verbose=False))],
verbose=False). Check the list of available parameters with estimator.get_params().keys().

让我去检查下keys(),那看一下吧:

pipe.get_params().keys()

返回:
dict_keys([‘memory’, ‘steps’, ‘verbose’, ‘smt’, ‘clf’, ‘smt__k_neighbors’, ‘smt__m_neighbors’, ‘smt__n_jobs’, ‘smt__out_step’, ‘smt__random_state’, ‘smt__sampling_strategy’, ‘smt__svm_estimator’, ‘clf__C’, ‘clf__break_ties’, ‘clf__cache_size’, ‘clf__class_weight’, ‘clf__coef0’, ‘clf__decision_function_shape’, ‘clf__degree’, ‘clf__gamma’, ‘clf__kernel’, ‘clf__max_iter’, ‘clf__probability’, ‘clf__random_state’, ‘clf__shrinking’, ‘clf__tol’, ‘clf__verbose’])

乍看之下,没毛病。
事实上,随便拿个参数 'smt__k_neighbors’举例, 这里的smt__ 有两道下划线。
再次强调,有两道下划线。__
写这个库的作者可能默认我们视力5.0.

  • 5
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值