Best Practices¶
Guidelines for getting the best results with Pilz.
Data Preparation¶
Feature Types¶
Choose correct statistical types:
# Good examples
features:
- name: status # "active", "inactive" → categorial
statistical: categorial
type: string
- name: age # 0-100 → numerical
statistical: numerical
type: int
- name: score # 0.0-100.0 → numerical
statistical: numerical
type: float
Missing Values¶
Always handle missing values:
If you do not set missing_value, nulls are not imputed — instead they become a
separate "missing" category that training and eval handle via IS NULL conditions.
Data Quality¶
-
Check for outliers before training
-
Ensure target column has no missing values
-
Use consistent value formats (e.g., "Yes" vs "yes")
Training Settings¶
Starting Point¶
Begin with these safe defaults:
Incrementally Increase Complexity¶
Parameter Guidelines¶
| Parameter | Low Value | High Value | Notes |
|-----------|-----------|------------|-------|
| n | 1 | 10+ | More trees = more accurate, slower |
| n_dims | 1 | 3 | Higher = more combinations, slower |
| n_cat | 3 | 10 | Higher = more bins, risk of overfitting |
| max_depth | 100 (default) | — | Leave at the default; min_eval_fit provides a more natural depth boundary |
| n_rep | 1 | 10+ | Higher = more stable cuts, slower |
n_rep also applies to multi-dimensional combinations. With n_dims > 1,
each feature combination is evaluated once per repetition using matching count
rows before its median candidate is selected. Increasing both n_dims and
n_rep can therefore increase training time substantially. Use
calcs_per_dim to cap the number of feature combinations evaluated at each
dimension.
Model Selection¶
Bias-Variance Trade-off¶
When to Use Feature Combinations¶
Consider higher n_dims (feature combinations) when:
- Single features do not separate the classes well
- Domain knowledge suggests interactions
- After establishing a baseline
Evaluation¶
Test Set¶
- Always hold out test data
- Don't use training data for evaluation
- Use stratified sampling for class balance
Metrics¶
- AUC: Overall discrimination ability
- Accuracy: Simple but can be misleading for imbalanced data
- Per-class accuracy: Important for multi-class
Deployment¶
Model Export¶
- Keep models in version control
- Document settings used
- Test with sample predictions
SQL Production¶
- Test SQL in staging before production
- Monitor prediction distributions
- Set up alerts for unusual patterns
Performance Checklist¶
- [ ] Data cleaned and validated
- [ ] Correct feature types set
- [ ] Missing values handled
- [ ] Started with baseline settings
- [ ] Incremental tuning
- [ ] Test set properly separated
- [ ] AUC > 0.8 (or domain-specific)
- [ ] SQL tested in staging
- [ ] Model versioned