13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

260

)

rf = RandomForestRegressor(

n_estimators=step_factor*(i+1),

n_jobs=n_jobs,

random_state=random_state

)

rf.fit(X_train, y_train)

mse = mean_squared_error(y_test, rf.predict(X_test))

estimators[i] = step_factor*(i+1)

rf_mse[i] = mse

# Estimate the AdaBoost MSE over the full number

# of estimators, across a step size ("step_factor")

for i in range(0, axis_step):

print("Boosting Estimator: %d of %d..." % (

step_factor*(i+1), n_estimators)

)

boosting = AdaBoostRegressor(

DecisionTreeRegressor(),

n_estimators=step_factor*(i+1),

random_state=random_state,

learning_rate=0.01

)

boosting.fit(X_train, y_train)

mse = mean_squared_error(y_test, boosting.predict(X_test))

estimators[i] = step_factor*(i+1)

boosting_mse[i] = mse

# Plot the chart of MSE versus number of estimators

plt.figure(figsize=(8, 8))

plt.title(’Bagging, Random Forest and Boosting comparison’)

plt.plot(estimators, bagging_mse, ’b-’, color="black", label=’Bagging’)

plt.plot(estimators, rf_mse, ’b-’, color="blue", label=’Random Forest’)

plt.plot(estimators, boosting_mse, ’b-’, color="red", label=’AdaBoost’)

plt.legend(loc=’upper right’)

plt.xlabel(’Estimators’)

plt.ylabel(’Mean Squared Error’)

plt.show()

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!