简体   繁体   English

精度得分错误:分类指标无法处理多类和连续目标的混合

[英]Precision score error: Classification metrics can't handle a mix of multiclass and continuous targets

I am currently in the process of trying to optimize a model for a certain performance metric using Hyperparameter tuning.我目前正在尝试使用超参数调整针对特定性能指标优化 model。 I did not receive the above error until I tried to tune my model specifically for the performance_score metric, when I just used my model as a normal predictor everything ran very smoothly, even when I added hyperparameter tuning it was fine.在我尝试专门针对 performance_score 指标调整 model 之前,我没有收到上述错误,当我刚刚使用 model 作为正常预测器时,一切都运行得非常顺利,即使我添加了超参数调整也很好。 Only when I tried to optimize it to a certain metric did it throw this error.只有当我尝试将其优化到某个指标时,它才会引发此错误。 This is the relevant code:这是相关代码:

scorers = {
    
    'precision_score': make_scorer(precision_score),
    'recall_score': make_scorer(recall_score),
    'accuracy_score': make_scorer(accuracy_score)
}
rf = RandomForestRegressor()
cv=KFold(n_splits=5,random_state=1,shuffle=False)
rf_rsearch = RandomizedSearchCV(estimator = rf, param_distributions = random_hypparams, scoring=scorers,refit='precision_score', return_train_score=True, n_iter = 50, cv = cv , verbose=2, n_jobs = -1)
rf_rsearch.fit(OS_x, OS_y)

In this code:在这段代码中:

  • random_hyperparams: is just a grid of randomized hyperparameters to be tested to find the best set. random_hyperparams:只是一个随机超参数网格,用于测试以找到最佳集合。
  • OS_x, OS_y are the x and y training set oversampled using SMC.With the respective shapes: (1290, 33) (1290,) OS_x, OS_y 是使用 SMC 过采样的 x 和 y 训练集。具有各自的形状:(1290, 33) (1290,)

The error seems to be occurring in the final line of the chunk of code displayed.该错误似乎发生在显示的代码块的最后一行。 Any help would be really great as I cannot find anything online which is similar to this problem.任何帮助都会非常棒,因为我在网上找不到与此问题类似的任何内容。

The error message indicates that the precision_score you are using does not support scoring the types of outputs/targets you are passing.错误消息表明您使用的precision_score 不支持对您传递的输出/目标类型进行评分。 Does this model make multiclass or continuous predictions?这个 model 是否进行多类或连续预测?

If this is a multiclass predictor, you should be able to optimize according to precision_score, but you need to define an average for the multiclass targets by passing one of 'micro', 'macro', 'samples', or 'weighted' to precision_score's average parameter as the default='binary (see documentation) .如果这是一个多类预测器,您应该能够根据precision_score进行优化,但是您需要通过将“micro”、“macro”、“samples”或“weighted”之一传递给precision_score来定义多类目标的平均值平均参数作为 default='binary (参见文档) The accepted answer to this StackOverflow post should help you do that with make_scorer. 这个 StackOverflow 帖子的公认答案应该可以帮助您使用 make_scorer 做到这一点。

If your model is making continuous predictions you will need to select a scorer that supports continuous output/target evaluation.如果您的 model 正在进行连续预测,您将需要 select 一个支持连续输出/目标评估的记分器。 The metrics under "Regression" in the scikit-learn documentation may help. scikit-learn 文档中“回归”下的指标可能会有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 混淆矩阵:ValueError:分类指标无法处理多类和连续多输出目标的混合 - Confusion matrix: ValueError: Classification metrics can't handle a mix of multiclass and continuous-multioutput targets hwo 修复 ValueError:分类指标无法处理多类和连续多输出目标的混合 - hwo to repair ValueError: Classification metrics can't handle a mix of multiclass and continuous-multioutput targets 如何处理 ValueError:分类指标无法处理多标签指标和多类目标错误的混合 - how to handle ValueError: Classification metrics can't handle a mix of multilabel-indicator and multiclass targets error 分类指标无法处理accuracy_score 中的连续目标和二进制目标的混合 - Classification metrics can't handle a mix of continuous and binary targets in accuracy_score 错误:分类指标无法处理多类多输出和多标记指标目标的混合 - Error: Classification metrics can't handle a mix of multiclass-multioutput and multilabel-indicator targets 混淆矩阵错误“分类指标无法处理多标签指标和多类目标的混合” - confusion matrix error "Classification metrics can't handle a mix of multilabel-indicator and multiclass targets" ValueError:分类指标无法处理连续目标和二元目标的混合 - ValueError: Classification metrics can't handle a mix of continuous and binary targets ValueError:分类指标无法处理二进制和连续目标的混合 - ValueError: Classification metrics can't handle a mix of binary and continuous targets 混淆矩阵() | ValueError:分类指标无法处理多类和多类多输出目标的混合 - confusion_matrix() | ValueError: Classification metrics can't handle a mix of multiclass and multiclass-multioutput targets ValueError:分类指标无法处理多标签指标和连续多输出目标错误的混合 - ValueError: Classification metrics can't handle a mix of multilabel-indicator and continuous-multioutput targets error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM