iv trained a model on my dataset like: from sklearn.modelselection import GridSearchCV…
- User
iv trained a model on my dataset like: from sklearn.model_selection import GridSearchCV from xgboost import XGBRegressor
Initialize the XGBoost model
xgb_regressor = XGBRegressor(objective='reg:squarederror', tree_method='gpu_hist')
Wrap XGBoost model with MultiOutputRegressor
multioutput_regressor = MultiOutputRegressor(xgb_regressor)
Define the parameter grid for XGBoost
param_grid = { 'estimator__n_estimators': [400,800], # Number of trees 'estimator__learning_rate': [0.2,2], # Step size shrinkage used to prevent overfitting 'estimator__max_depth': [8,16], # Maximum depth of a tree # Add more parameters here based on your needs }
Initialize GridSearchCV
grid_search = GridSearchCV(estimator=multioutput_regressor, param_grid=param_grid, cv=3, n_jobs=-1, verbose=2, scoring='neg_mean_absolute_error')
Train the model using grid search to find the best hyperparameters
grid_search.fit(X_train_scaled, Y_train_scaled)
Print the best parameters and the best score
print(f"Best parameters: {grid_search.best_params_}") print(f"Best score: {grid_search.best_score_}")
how can i see mae of model performance on test and dev set?
- Assistant
To evaluate the performance of your trained model on the test and dev sets in terms of Mean Absolute Error (MAE), you can use Scikit-learn's
mean_absolute_errorfunction from themetricsmodule. Assuming you have your test set (X_test_scaled,Y_test_scaled) and dev set (X_dev_scaled,Y_dev_scaled) ready, you can use the best model obtained through GridSearchCV to make predictions on these sets and then calculate the MAE. Here's how you can do it:from sklearn.metrics import mean_absolute_error # Make predictions on the test set using the best model found by GridSearchCV Y_test_pred_scaled = grid_search.best_estimator_.predict(X_test_scaled) # Calculate the MAE for the test set test_mae = mean_absolute_error(Y_test_scaled, Y_test_pred_scaled) print(f"Test MAE: {test_mae}") # If you have a dev set, do the same for the dev set # Make predictions on the dev set Y_dev_pred_scaled = grid_search.best_estimator_.predict(X_dev_scaled) # Calculate the MAE for the dev set dev_mae = mean_absolute_error(Y_dev_scaled, Y_dev_pred_scaled) print(f"Dev MAE: {dev_mae}")