You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用adabag包predict.boosting函数报错:newmfinal需满足1<newmfinal<mfinal

解决adabag包predict.boosting报错问题

问题根源

你用boosting.cv()训练的是交叉验证评估模型,这个函数的返回值是交叉验证的性能结果,不是可用于预测的boosting模型对象,所以用predict.boosting()去调用它肯定报错,和newmfinal的数值无关。

修正方案

如果要做预测,得先使用普通的boosting()函数训练模型,再用predict.boosting()进行预测:

install.packages("adabag")
library("adabag")

# 1. 用boosting()训练可用于预测的模型
adaboost_model <- boosting(factor_new ~ RFS +LI+SDI+LDI+DR+DBT+FCT+FII+DITP+ADCG+ADDG+ROA+ROI+ROS+ROE,
                           data = train01_new, 
                           boos = TRUE, 
                           mfinal = 10, 
                           control = rpart.control(cp=.001))

# 2. 用predict.boosting()预测,此时newmfinal可以设为1到10之间的整数(比如9)
predict_adaboost_train <- predict.boosting(adaboost_model, train01_new, newmfinal = 9)

补充说明

  • boosting.cv()的作用是通过交叉验证评估模型的泛化能力,输出的是准确率、混淆矩阵这些评估指标,不能直接用来做预测。
  • 如果需要先通过交叉验证确定最优的mfinal参数,再训练最终模型,可以先运行boosting.cv()得到最优迭代次数,再代入boosting()中训练。

内容的提问来源于stack exchange,提问作者Alfredo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 09:52:08