Optimize LightGBM Hyperparameters
Provides templates and guidance for LightGBM hyperparameter tuning with Optuna, cross-validation, and parameter prioritization for binary, multiclass, and
Why it matters
Automate the hyperparameter tuning process for LightGBM models to achieve optimal performance and efficiency.
Outcomes
What it gets done
Implement a multi-stage tuning pipeline using Optuna.
Apply parameter prioritization and search strategy hierarchy.
Incorporate advanced techniques like successive halving and Bayesian optimization.
Generate production-ready configurations for memory and speed optimization.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/vb-lightgbm-tuning-script | bash Overview
LightGBM Hyperparameter Tuning Expert
This skill provides templates and guidance for creating LightGBM hyperparameter tuning scripts using Optuna. It offers a `LightGBMTuner` class template with cross-validation logic, task-specific configurations for binary, multiclass, and regression problems, and parameter search space definitions. Use this skill when you need structured guidance for optimizing LightGBM models with proper cross-validation and task-specific metrics. It's helpful when you want to follow parameter tuning best practices with informed search ranges and early stopping.
What it does
This skill provides templates and expertise for creating LightGBM hyperparameter tuning scripts using Optuna. It offers a LightGBMTuner class template with cross-validation logic, task-specific configurations for binary, multiclass, and regression problems, and parameter search space definitions. The source material includes parameter prioritization guidance (primary parameters: num_leaves, learning_rate, feature_fraction, bagging_fraction; secondary: min_data_in_leaf, lambda_l1, lambda_l2, min_gain_to_split; advanced: max_depth, bagging_freq, max_bin) and production configuration helpers for memory and speed optimization.
When to use - and when NOT to
Use this skill when you need structured guidance for optimizing LightGBM models with proper cross-validation and task-specific metrics (AUC for binary, log loss for multiclass, RMSE for regression). It's helpful when you want to follow parameter tuning best practices with informed search ranges and early stopping. Do NOT use this for quick prototyping where default parameters suffice, or when you lack sufficient data for meaningful cross-validation (the template uses 5-fold CV by default). Avoid it if you need real-time tuning - the template is designed for offline optimization with configurable trial counts.
Inputs and outputs
You provide your feature matrix (X), target variable (y), task type ('binary', 'multiclass', or 'regression'), number of CV folds, and trial count to the LightGBMTuner class template. The template handles parameter search spaces for Optuna trials, cross-validation splitting (StratifiedKFold for classification, KFold for regression), and scoring logic. The objective function evaluates parameters across CV folds using LightGBM's training API with early stopping and returns mean scores.
Integrations
The template integrates with LightGBM for model training with early stopping callbacks, Optuna for hyperparameter optimization trials, scikit-learn for StratifiedKFold and KFold cross-validation plus metrics (roc_auc_score, mean_squared_error), and NumPy for score aggregation. It uses LightGBM's Dataset format and training API.
Example usage
import lightgbm as lgb
import optuna
import numpy as np
from sklearn.model_selection import StratifiedKFold, cross_val_score
from sklearn.metrics import roc_auc_score, mean_squared_error
import warnings
warnings.filterwarnings('ignore')
class LightGBMTuner:
def __init__(self, X, y, task_type='binary', cv_folds=5, n_trials=100):
self.X = X
self.y = y
self.task_type = task_type
self.cv_folds = cv_folds
self.n_trials = n_trials
self.best_params = None
self.best_score = None
# Task-specific configurations
self.config = self._get_task_config()
def _get_task_config(self):
configs = {
'binary': {
'objective': 'binary',
'metric': 'auc',
'eval_metric': roc_auc_score,
'mode': 'maximize'
},
'multiclass': {
'objective': 'multiclass',
'metric': 'multi_logloss',
'eval_metric': 'neg_log_loss',
'mode': 'maximize'
},
'regression': {
'objective': 'regression',
'metric': 'rmse',
'eval_metric': 'neg_root_mean_squared_error',
'mode': 'maximize'
}
}
return configs[self.task_type]
Who it's for
This skill serves machine learning engineers and data scientists building LightGBM models who need structured templates for hyperparameter optimization. It's valuable for practitioners working on classification or regression problems who want to follow parameter tuning best practices with proper cross-validation and task-specific metrics.
FAQ
Common questions
Discussion
Questions & comments ยท 0
Sign In Sign in to leave a comment.