0
rf = RandomForestRegressor()
grid = GridSearchCV(rf,param_grid=param_grid,cv=3,n_jobs=8)
grid.fit(train_X,train_y)

I use RandomForestRegressor like the codes above. And, I want to get the train_error. How can I do that?

to be more specific:(1)can I get the "train_error" from the RandomForestRegressor ? (2) If I use "the mean_squared_error", how can I get the predicted value of the train data.

some pictures for my question.

enter image description here enter image description here

Nipun Thennakoon
  • 3,586
  • 1
  • 18
  • 26
user10025959
  • 55
  • 1
  • 7

1 Answers1

0

(1)

You can use .cv_results_ to get the mean squared error of each iterations. (Your cv=3 so there should be 3 of them).

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

(2)

I think you couldn't get the predicted values with GridSearchCV. You might need to implement it by yourself.

ujhuyz0110
  • 383
  • 1
  • 8
  • The method(1) above returned results like this: -0.143476163479 -0.114397135622 -0.0652798450285 -0.0444094919283 -0.0803082980101 -0.100409404264 -0.167920444638...... these maybe not train_error. – user10025959 Jul 13 '18 at 01:03
  • I use grid.best_score_ to get a number 0.13028393891466461. Dose it means the mean_squared_error? – user10025959 Jul 13 '18 at 01:21
  • @user10025959, The actual those negative values are actually just the negative MSE. In GridSearchCV, to minimize MSE, the algorithm simply just maximizes the negative MSE. You could read more about it here: [https://stackoverflow.com/questions/21443865/scikit-learn-cross-validation-negative-values-with-mean-squared-error](https://stackoverflow.com/questions/21443865/scikit-learn-cross-validation-negative-values-with-mean-squared-error) – ujhuyz0110 Jul 13 '18 at 01:53
  • Thank you for help. I think I have got it . – user10025959 Jul 13 '18 at 02:16