Answer to: XGBoost Pipeline with ColumnTransformer: Handling categorical + numerical data and improving accuracy
Score: 0
You can use grid search to improve
from sklearn.model_selection import GridSearchCV
# Define hyperparameter grid
param_grid = {
'classifier__n_estimators': [100, 200],
'classifier__max_depth': [3, 5, 7],
'classifier__learning_rate': [0.01, 0.1],
'classifier__subsample': [0.8, 1.0],
'classifier__colsample_bytree': [0.8, 1.0]
}
# Initialize GridSearchCV
grid_search = GridSearchCV(
estimator=model, # your existing pipeline
param_grid=param_grid,
cv=5,
scoring='accuracy',
n_jobs=-1,
verbose=1
)
# Fit grid search on training data
print("Running Grid Search...")
grid_search.fit(X_train, y_train)
# Get best model
best_model = grid_search.best_estimator_
print("Best Parameters:", grid_search.best_params_)
View Question ↗
Question
Parent Entity
Score: 2 • Views: 51
Site: stackoverflow
SaaS Metrics