To tune hyperparameters for a Random Forest model in Scikit-learn, use GridSearchCV, which performs an exhaustive search over a specified parameter grid, evaluating the best combination using cross-validation.
Here is the code snippet given below:

In the above code we are using the following techniques:
- Defines a Search Grid: Tunes n_estimators, max_depth, min_samples_split, min_samples_leaf, and bootstrap.
- Uses GridSearchCV: Performs exhaustive search with 5-fold cross-validation for optimal hyperparameters.
- Parallel Processing (n_jobs=-1): Speeds up computation by utilizing all available CPU cores.
- Retrieves Best Model: Stores the best hyperparameters in grid_search.best_params_ and best model in grid_search.best_estimator_.
- Evaluates on Test Data: Ensures that hyperparameter tuning improves real-world model performance.
Hence, GridSearchCV systematically finds the best hyperparameters for a Random Forest model using cross-validation, ensuring optimal performance while preventing overfitting.