【问题标题】:How to get the train_error of RandomForestRegressior如何获得随机森林回归器的训练误差
【发布时间】:2018-12-21 07:11:33
【问题描述】:
rf = RandomForestRegressor()
grid = GridSearchCV(rf,param_grid=param_grid,cv=3,n_jobs=8)
grid.fit(train_X,train_y)

我像上面的代码一样使用 RandomForestRegressor。而且,我想得到 train_error。我该怎么做?

更具体地说:(1)我可以从 RandomForestRegressor 中得到“train_error”吗? (2) 如果我使用“the mean_squared_error”,如何得到训练数据的预测值。

我的问题的一些图片。

【问题讨论】:

    标签: python random-forest mse


    【解决方案1】:

    (1)

    您可以使用.cv_results_ 获取每次迭代的均方误差。 (你的 cv=3 所以应该有 3 个)。

    cvres = grid.cv_results_
    for mean_score in cvres['mean_test_score']:
        print(mean_score)
    

    (2)

    我认为您无法使用GridSearchCV 获得预测值。您可能需要自己实现它。

    【讨论】:

    • 上面的方法(1)返回的结果是这样的:-0.143476163479 -0.114397135622 -0.0652798450285 -0.0444094919283 -0.0803082980101 -0.100409404264 -0.16792
    • 我使用 grid.best_score_ 得到一个数字 0.13028393891466461。剂量是否意味着 mean_squared_error?
    • @user10025959,实际那些负值实际上只是负 MSE。在 GridSearchCV 中,为了最小化 MSE,算法只是最大化负 MSE。你可以在这里阅读更多信息:https://stackoverflow.com/questions/21443865/scikit-learn-cross-validation-negative-values-with-mean-squared-error
    • 感谢您的帮助。我想我明白了。
    猜你喜欢
    • 2018-12-06
    • 1970-01-01
    • 2021-03-21
    • 1970-01-01
    • 2013-05-06
    • 2019-04-24
    • 2019-03-22
    • 2017-01-22
    • 2018-06-13
    相关资源
    最近更新 更多