Question: correct the code # Hyperparameter tuning using Grid Search param_dist = { 'n_estimators': [100, 200, 300], 'learning_rate': [0.01, 0.1, 0.2], 'max_depth': [3, 4, 5], 'min_samples_split':
correct the code # Hyperparameter tuning using Grid Search param_dist = { 'n_estimators': [100, 200, 300], 'learning_rate': [0.01, 0.1, 0.2], 'max_depth': [3, 4, 5], 'min_samples_split': [2, 5, 10], 'min_samples_leaf': [1, 2, 4] } random_search = RandomizedSearchCV(estimator=model_gbm_z1, param_distributions=param_dist, n_iter=50, cv=3, n_jobs=-1, verbose=2, random_state=42) with parallel_backend('threading'): random_search.fit(X_train_sc_z1, y_train_sc_z1) # Best parameters print("Best parameters found: ", random_search.param_dist) # Train the model with the best parameters best_gbm = grid_search.best_estimator_ best_gbm.fit(X_train_sc_z1, y_train_sc_z1) # Make predictions y_pred = best_gbm.predict(X_test_sc_z1) # Evaluate the model mae = mean_absolute_error(y_test_sc_z1, y_pred) rmse = np.sqrt(mean_squared_error(y_test_sc_z1, y_pred)) print(f'Mean Absolute Error: {mae}') print(f'Root Mean Squared Error: {rmse}') # Plot results import matplotlib.pyplot as plt plt.figure(figsize=(12, 6)) plt.plot(y_test_sc_z1, label='True') plt.plot(y_pred, label='Predicted') plt.legend() plt.show()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
