Tune Hyperparameters
Hyperparameter tuning finds the optimal settings for your model. MLOps Desktop integrates Optuna for intelligent hyperparameter search with three strategies: Bayesian (TPE), Random, and Grid.
Time to complete: ~15 minutes
Prerequisites
Section titled “Prerequisites”- Completed the Quickstart tutorial
- Python packages:
pip install optuna
Enable Hyperparameter Tuning
Section titled “Enable Hyperparameter Tuning”-
Open your pipeline
Load a pipeline with DataLoader → DataSplit → Trainer → Evaluator.
-
Select Tune mode
Click the Trainer node. At the top of the node, click the Tune button (next to Train and Load).
-
Configure model and target
- Model Type: Select any model except Linear Regression (no tunable params)
- Target Column: Your target variable
-
Open Tuning Configuration
Click the Configure Tuning button to open the TuningPanel.
-
Set tuning parameters
Setting Recommended Range Search Strategy Bayesian (TPE) TPE, Random, Grid Number of Trials 50 1-1000 CV Folds 3 2-10 Scoring Metric accuracy (classification) or r2 (regression) varies -
Run the pipeline
Click Run. Watch the Trials tab for real-time results.
Search Strategies
Section titled “Search Strategies”Tree-structured Parzen Estimator — Default and recommended.
- Learns from previous trials to focus on promising regions
- Most efficient for complex search spaces
- Better results with fewer trials
Trial 1-10: Exploration (random-ish)Trial 11+: Exploitation (focuses on good regions)Random Search — Simple uniform sampling.
- Each trial is independent
- Good baseline for comparison
- Works well with large search spaces
Every trial: Random sample from full spaceGrid Search — Exhaustive enumeration.
- Tests every combination
- Only practical for small, discrete spaces
- Warning shown if >10,000 combinations
All combinations of:n_estimators: [50, 100, 150]max_depth: [5, 10, 15]= 9 total trialsSearch Spaces by Model
Section titled “Search Spaces by Model”Each model has predefined search ranges optimized for common use cases:
Random Forest
Section titled “Random Forest”| Parameter | Range | Type |
|---|---|---|
n_estimators | 50-300 (step 50) | Integer |
max_depth | [None, 10, 15, 20, 30] | Categorical |
min_samples_split | 2-10 (step 2) | Integer |
min_samples_leaf | 1-4 (step 1) | Integer |
Gradient Boosting
Section titled “Gradient Boosting”| Parameter | Range | Type |
|---|---|---|
n_estimators | 50-300 (step 50) | Integer |
learning_rate | 0.01-0.3 | Log-uniform |
max_depth | 3-8 (step 1) | Integer |
subsample | 0.7-1.0 | Uniform |
SVM (SVC/SVR)
Section titled “SVM (SVC/SVR)”| Parameter | Range | Type |
|---|---|---|
C | 0.1-100 | Log-uniform |
kernel | [rbf, linear, poly] | Categorical |
gamma | [scale, auto] | Categorical |
| Parameter | Range | Type |
|---|---|---|
n_neighbors | 3-21 (step 2) | Integer |
weights | [uniform, distance] | Categorical |
metric | [euclidean, manhattan, minkowski] | Categorical |
MLP Neural Network
Section titled “MLP Neural Network”| Parameter | Range | Type |
|---|---|---|
hidden_layer_sizes | [(50,), (100,), (100,50), (100,100)] | Categorical |
alpha | 0.0001-0.1 | Log-uniform |
learning_rate_init | 0.0001-0.1 | Log-uniform |
max_iter | 200-1000 (step 100) | Integer |
Logistic Regression
Section titled “Logistic Regression”| Parameter | Range | Type |
|---|---|---|
C | 0.01-100 | Log-uniform |
max_iter | 500-2000 (step 500) | Integer |
Scoring Metrics
Section titled “Scoring Metrics”Choose the metric to optimize:
Classification:
| Metric | Best For |
|---|---|
accuracy | Balanced classes (default) |
f1 | Imbalanced classes |
precision | Minimize false positives |
recall | Minimize false negatives |
roc_auc | Ranking quality |
Regression:
| Metric | Best For |
|---|---|
r2 | Overall fit (default) |
neg_mse | Penalize large errors |
neg_mae | Robust to outliers |
neg_rmse | Same units as target |
Trials Tab
Section titled “Trials Tab”During tuning, the Trials tab shows real-time results:
| Column | Description |
|---|---|
| # | Trial number |
| Score | Cross-validation score (higher = better) |
| Parameters | Hyperparameter values tried |
| Duration | Time for this trial |
| Status | Complete, Pruned, or Failed |
The best trial is highlighted with a star icon.
Example Output
Section titled “Example Output”Trial 1: 0.823 n_estimators=150, max_depth=10 2.1sTrial 2: 0.845 n_estimators=200, max_depth=15 2.8sTrial 3: 0.831 n_estimators=100, max_depth=None 1.9s...★ Trial 17: 0.867 n_estimators=250, max_depth=20 3.2s ← BestCross-Validation
Section titled “Cross-Validation”Tuning uses k-fold cross-validation (not a simple train/test split):
- Training data split into k folds
- Model trained k times, each time validating on a different fold
- Scores averaged for final trial score
This provides more reliable scoring than a single split.
| CV Folds | Trade-off |
|---|---|
| 2 | Fast, high variance |
| 3 | Good balance (default) |
| 5 | More reliable, slower |
| 10 | Most reliable, slowest |
After Tuning
Section titled “After Tuning”When tuning completes:
- Best parameters are displayed in the Trials tab
- Final model is trained on full training data with best params
- Evaluator receives the tuned model for metrics
The best configuration is automatically applied—no manual copying needed.
Tips for Better Results
Section titled “Tips for Better Results”Start Small
Section titled “Start Small”Begin with 20-30 trials to understand the landscape:
Trial 1-30: Quick exploration→ Review results→ Narrow search space if needed→ Run 50-100 more trialsUse TPE for Most Cases
Section titled “Use TPE for Most Cases”Bayesian (TPE) outperforms Random search in almost all scenarios. Only use Grid when:
- You have a very small search space
- You need exhaustive coverage
Increase CV Folds for Small Data
Section titled “Increase CV Folds for Small Data”With fewer than 1,000 samples, use 5-fold CV to get reliable scores.
Check for Overfitting
Section titled “Check for Overfitting”If tuning score is much higher than evaluation score, your model may be overfitting to the validation folds. Try:
- Simpler model (fewer estimators, shallower trees)
- More regularization (
Cfor SVM,alphafor MLP)
Common Issues
Section titled “Common Issues””Optuna not installed"
Section titled “”Optuna not installed"”pip install optuna"Linear Regression cannot be tuned”
Section titled “"Linear Regression cannot be tuned””Linear Regression has no hyperparameters. Use Ridge, Lasso, or another model.
Tuning takes too long
Section titled “Tuning takes too long”- Reduce number of trials (20-30 for quick tests)
- Use Random instead of Grid search
- Reduce CV folds to 2
- Use a simpler model (Logistic Regression vs MLP)
Grid search warning
Section titled “Grid search warning”If Grid search shows “>10,000 combinations”, the search space is too large. Switch to TPE or Random.