0

I want to have root mean squared of gradient boosting algorithm but when I want to print it, I receive an attribute error

my_best_model.np.sqrt(metrics.mean_squared_error(X_test_new, y_test_new))


output:

AttributeError                            Traceback (most recent call last)
<ipython-input-80-9c2e86b2ddf9> in <module>
----> 1 my_best_model.np.sqrt(metrics.mean_squared_error(X_test_new, y_test_new))

AttributeError: 'GradientBoostingRegressor' object has no attribute 'np'
desertnaut
  • 57,590
  • 26
  • 140
  • 166
CFD
  • 607
  • 1
  • 11
  • 29
  • 1
    `np.sqrt(sklearn.metrics.mean_squared_error(my_best_model.predict(X_test_new), y_test_new))` – Frayal Mar 22 '19 at 14:55

1 Answers1

2

This is not the correct usage; assuming that my_best_model is a fitted GradientBoostingRegressor, you should use:

from sklearn.metrics import mean_squared_error

mse = mean_squared_error(y_test_new, my_best_model.predict(X_test_new))
rmse = np.sqrt(mse)
desertnaut
  • 57,590
  • 26
  • 140
  • 166
  • Thanks it worked. But how could I run this code without error? my_best_model.score(X_test_new, y_test_new) I think they are the same – CFD Mar 22 '19 at 15:00
  • 1
    @CFD The `score` attribute is model-specific, and for GBR is the coefficient of determination R^2 and *not* the MSE ([docs](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.GradientBoostingRegressor.html#sklearn.ensemble.GradientBoostingRegressor.score)). It is good idea to avoid it, but nevertheless your code should not produce any error. – desertnaut Mar 22 '19 at 15:03
  • This is what I get from my model. How do you think about that? Tuned Model R2 Accuracy of Training Data: 72.86% Tuned Model R2 Accuracy of Testing Data: 44.46% Tuned Model RMSE Accuracy of Testing Data:45164.39101312308 – CFD Mar 22 '19 at 15:07
  • 1
    @CFD comments are not the right place for such discussions, plus that I know nothing of your data & problem; in general 1) terminology like "R^2 accuracy" and "RMSE accuracy" are not correct - we normally save the term "accuracy" for classification problems 2) I suggest you don't even bother with R^2 - see the last part of my answer for [scikit-learn & statsmodels - which R-squared is correct?](https://stackoverflow.com/questions/54614157/scikit-learn-statsmodels-which-r-squared-is-correct/54618898#54618898) – desertnaut Mar 22 '19 at 15:12