liveBook · Manning

Hyperparameter tuning

As explained in Financial AI in Practice

Hyperparameter tuning is the process of selecting configuration values for a model’s learning procedure to improve its performance.

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

How Financial AI in Practice covers it

How deep it goes
Works through randomized search, fold-level resampling, refitting, and test evaluation; mentions grid and Bayesian search without implementing them.
Examples
Uses a fraud pipeline tuned for recall, fixed XGBoost settings in credit scoring, and conservative random forest settings for market prediction.
What you can do after
Apply scikit-learn RandomizedSearchCV to select and refit a fraud-detection pipeline before evaluating it on unseen test data.
How it connects
Connects hyperparameter search with cross-validation, SMOTE, LightGBM, XGBoost, random forests, and overfitting control.

Also explained in

Compare how 18 books explain hyperparameter tuning →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Financial AI in Practice. The section links point to the parts of the book it draws on.