随机森林算法java,scikit-learn随机森林:严重过度拟合?

我试图应用knn,逻辑回归,决策树和随机森林来预测二元响应变量 .

前三个产生看似合理的准确率,但运行随机森林算法产生的准确率超过99%(1127/1128正确) .

vote_lst = list(range(1, 101))

rf_cv_scores = []

for tree_count in vote_lst:

maple = RandomForestClassifier(n_estimators = tree_count, random_state = 1618)

scores = cross_val_score(maple, x, y, cv = 10, scoring = 'accuracy') # 10-fold CV

rf_cv_scores.append(scores.mean())

# find minimum error's index (i.e. optimal num. of estimators)

rf_MSE = [1 - x for x in rf_cv_scores]

min_error = rf_MSE[0]

for i in range(len(rf_MSE)):

min_error = min_error

if rf_MSE[i] < min_error:

rf_min_index = i

min_error = rf_MSE[i]

print(rf_min_index + 1) # error minimized w/ 66 estimators

我使用上面的代码调整了rf算法超参数 n_estimators . 然后,我在我的数据上拟合模型:

# fit random forest classifier

forest_classifier = RandomForestClassifier(n_estimators = rf_min_index + 1, random_state = 1618)

forest_classifier.fit(x, y)

# predict test set

y_pred_forest = forest_classifier.predict(x)

我担心这里发生了一些严重的过度拟合:任何想法?

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值