Skip to content

Commit

Permalink
simple ensemble method using random forest and AdaBoost
Browse files Browse the repository at this point in the history
  • Loading branch information
SaurabhIndi authored Oct 7, 2024
1 parent 41328e5 commit c5e8845
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Stock_Price_Prediction(Updated).ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5215,6 +5215,46 @@
"plt.tight_layout()\n",
"plt.show()\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This code demonstrates a simple ensemble method using random forest and AdaBoost. It combines the predictions of these two models by taking their average. You can experiment with different ensemble techniques like stacking or voting, and adjust the hyperparameters of the individual models to find the best combination for your specific problem."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from sklearn.ensemble import RandomForestRegressor, AdaBoostRegressor\n",
"from sklearn.model_selection import train_test_split\n",
"from sklearn.metrics import mean_squared_error\n",
"\n",
"# Assuming you have your features (X) and target variable (y)\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
"\n",
"# Create individual models\n",
"rf_model = RandomForestRegressor(n_estimators=100, random_state=42)\n",
"adaboost_model = AdaBoostRegressor(n_estimators=100, random_state=42)\n",
"\n",
"# Train the models\n",
"rf_model.fit(X_train, y_train)\n",
"adaboost_model.fit(X_train, y_train)\n",
"\n",
"# Make predictions\n",
"rf_predictions = rf_model.predict(X_test)\n",
"adaboost_predictions = adaboost_model.predict(X_test)\n",
"\n",
"# Combine predictions (simple averaging)\n",
"ensemble_predictions = (rf_predictions + adaboost_predictions) / 2\n",
"\n",
"# Evaluate the ensemble model\n",
"ensemble_mse = mean_squared_error(y_test, ensemble_predictions)\n",
"print(\"Ensemble MSE:\", ensemble_mse)"
]
}
],
"metadata": {
Expand Down

0 comments on commit c5e8845

Please sign in to comment.