Hyperparameter tuning selects configuration values for a model’s learning procedure to improve performance. In fraud detection, randomized search compares LightGBM and SMOTE pipeline settings using cross-validated recall, then refits the best pipeline for evaluation on an untouched test set. section 8.3.2
A practical search workflow can:
- Sample 10 hyperparameter combinations and assess each with five-fold cross-validation. section 8.3.2
- Apply SMOTE only to each fold’s training data before fitting LightGBM, supporting an unbiased comparison. section 8.3.2
- Select settings by cross-validated fraud recall, refit the winning pipeline on the full training set, and evaluate it on the separate test set. section 8.3.2
Search strategy and safeguards depend on the task. Credit scoring may use grid search or Bayesian optimization instead of fixed XGBoost settings. For market prediction, conservative random forest settings limit tree depth and split complexity to reduce fitting noise; out-of-sample predictive results still do not account for trading costs or constraints. section 5.3.5 section 10.5.5
Listing 8.4 Performing RandomizedSearchCV to train and tune the model
print("\nStarting RandomizedSearchCV (cv=5, n_iter=10) to train the LightGBM model...")
print("This process may take several minutes. Verbose output will show progress.")
# Fit RandomizedSearchCV on the original imbalanced training data
random_search_final.fit(X_train, y_train) #1
print("\nRandomizedSearchCV hyperparameter tuning completed.")
print("--------------------------------------------------")
# Display the best parameters found
print("Best parameters found by RandomizedSearchCV:")
print(random_search_final.best_params_) #2
print("\nBest cross-validated recall score (for fraud class) achieved during search:")
print(f"{random_search_final.best_score_:.4f}") #3
print("--------------------------------------------------")
# The best_estimator_ attribute now holds our optimally tuned pipeline
best_model_final = random_search_final.best_estimator_ #4
Runnable RandomizedSearchCV example for training and tuning a LightGBM fraud-detection pipeline. section 8.3.2

















