image_output_1.png
from scipy import stats

from sklearn import metrics

from sklearn.ensemble import GradientBoostingRegressor

import numpy as np

max_r2 = 0
for i in np.linspace(0.1, 1, 50):
    gbr = GradientBoostingRegressor(learning_rate=i)
    gbr.fit(x_train, y_train)
    y_pred = gbr.predict(x_test)
    print('For learning rate i: %0.2f' % i)
    print('Gradient Boosting Regression MAE: %0.5f' % metrics.mean_absolute_error(y_test, y_pred))
    print('Gradient Boosting MSE:%0.5f' % metrics.mean_squared_error(y_test, y_pred))
    print('Gradient Boosting RMSE:%0.5f' % np.sqrt(metrics.mean_squared_error(y_test, y_pred)))
    print('Gradient Boosting R^2: %0.5f' % metrics.explained_variance_score(y_test, y_pred))
    print('---------------------------------')
    if metrics.explained_variance_score(y_test, y_pred) > max_r2:
        max_r2 = metrics.explained_variance_score(y_test, y_pred)
        max_i = i
        y_pred_gbr = y_pred
        se_gbr = stats.sem(y_pred_gbr)
print('Max R^2 is: %0.5f' % max_r2, 'with learning rate: %0.2f' % max_i)