HistGradientBoosting / Classifier Layer
Histogram-based Gradient Boosting Classification: A high-performance tree-based ensemble method.
Mathematical formulation: where:
- is the model after m iterations
- is the learning rate
- is the weak learner (decision tree)
Key characteristics:
- Histogram-based binning for fast training
- Memory-efficient implementation
- Automatic handling of missing values
- Native support for categorical features
- Advanced early stopping mechanisms
Performance benefits:
- 10-100x faster than traditional GBM
- Excellent for large datasets (n_samples > 10,000)
- Reduced memory footprint
- Competitive accuracy with state-of-the-art
Common applications:
- Click-through rate prediction
- Customer churn analysis
- Risk modeling
- Fraud detection
- Recommendation systems
Outputs:
- Predicted Table: Input data with predictions
- Validation Results: Cross-validation metrics
- Test Metric: Hold-out set performance
- ROC Curve Data: Classification quality analysis
- Confusion Matrix: Detailed class predictions
- Feature Importances: Variable contribution scores
SelectFeatures
[column, ...]Feature columns for Histogram Gradient Boosting Classification:
Data requirements:
-
Supported types:
- Numeric (int, float)
- Categorical (auto-detected)
- Boolean features
- Missing values allowed
-
Preprocessing recommendations:
- Remove constant features
- Handle extreme outliers
- Check feature correlations
- Ensure data quality
-
Performance considerations:
- Number of features impacts memory
- Categorical cardinality affects binning
- Feature count influences training speed
- Storage requirements scale with features
-
Best practices:
- Start with known important features
- Monitor feature importance
- Remove redundant features
- Consider feature interactions
Note: If empty, automatically uses all suitable numeric columns except target
SelectTarget
columnTarget column for classification tasks:
Requirements:
-
Data characteristics:
- Categorical labels
- At least two classes
- No missing values
- Consistent encoding
-
Class properties:
- Binary or multiclass
- Class distribution noted
- Class encoding verified
- Meaningful categories
-
Quality checks:
- Label consistency
- Class balance/imbalance
- Error costs understood
- Domain validity confirmed
-
Modeling considerations:
- Stratification needs
- Metric selection
- Class weighting strategy
- Evaluation approach
Note: Must be a single column containing class labels
Params
oneofOptimized default configuration for Histogram Gradient Boosting Classification:
Core parameters:
- Learning rate: 0.1 (balanced speed/accuracy)
- Max iterations: 100 (convergence limit)
- Max leaf nodes: 31 (tree complexity)
- Min samples leaf: 20 (overfitting control)
Training control:
- Early stopping: auto enabled
- Validation fraction: 0.1
- Tolerance: 1e-7
- L2 regularization: 0.0
System settings:
- Max bins: 255 (histogram precision)
- Warm start: disabled
- Class weights: None
Best suited for:
- Initial modeling
- Balanced datasets
- Medium-sized problems
- Quick prototyping
Custom model parameters.
LearningRate
f64The learning rate, also known as shrinkage. This is used as a multiplicative factor for the leaves values. Use 1 for no shrinkage.
Mathematical impact: where is the learning rate
Trade-offs:
- Lower values: Better accuracy, slower training
- Higher values: Faster training, potential instability
Typical ranges:
- Conservative: 0.01-0.05
- Standard: 0.1 (default)
- Aggressive: 0.2-0.3
Note: Smaller learning rates require more iterations
MaxIter
u32The maximum number of iterations of the boosting process, i.e. the maximum number of trees for binary classification. For multiclass classification, n_classes trees per iteration are built.
Impact:
- Model complexity
- Training time
- Convergence guarantee
- Final ensemble size
Selection guidelines:
- Simple problems: 50-100
- Medium complexity: 100-500
- Complex problems: 500-2000
Interaction notes:
- Inversely related to learning rate
- Early stopping may reduce actual iterations
- Higher values needed for smaller learning rates
MaxLeafNodes
u32The maximum number of leaves for each tree. Cannot be equal to 1. If 0, there is no maximum limit.
Controls:
- Tree complexity
- Model capacity
- Memory usage
- Training speed
Guidelines:
- Small (15-31): Simple problems
- Medium (32-127): Standard datasets
- Large (128+): Complex relationships
Trade-offs:
- More leaves: Better accuracy, higher complexity
- Fewer leaves: Faster training, better generalization
Note: Set to 0 for unlimited nodes
MaxDepth
u32The maximum depth of each tree. The depth of a tree is the number of edges to go from the root to the deepest leaf.
Effects:
- Controls tree hierarchy levels
- Limits feature interactions
- Manages model complexity
- Influences training time
Typical values:
- Shallow (3-5): Simple relationships
- Medium (6-10): Standard problems
- Deep (11+): Complex interactions
Considerations:
- Memory usage grows exponentially with depth
- Deeper trees risk overfitting
- Set to 0 for unlimited depth
Minimum samples required at leaf nodes:
Purpose:
- Prevents overfitting
- Ensures statistical significance
- Controls tree granularity
- Stabilizes predictions
Selection guide:
- Small datasets (<1000): 5-10 samples
- Medium datasets: 20-50 samples
- Large datasets: 50-100+ samples
Impact:
- Higher values: More stable, less detailed
- Lower values: More detailed, risk of overfitting
L2 regularization strength:
Mathematical form:
Effects:
- Controls leaf weight smoothing
- Reduces overfitting
- Improves generalization
Typical values:
- None: 0.0
- Weak: 0.1-1.0
- Strong: 5.0-10.0
Note: Higher values mean stronger regularization
MaxFeatures
f64Fraction of features to consider for splits:
Purpose:
- Introduces randomness
- Reduces correlation between trees
- Prevents overfitting
- Speeds up training
Common settings:
- 1.0: Use all features (default)
- 0.7-0.8: Standard random selection
- sqrt(n)/n: Traditional random forest style
Note: Lower values increase randomization but may miss important features
MaxBins
u32The maximum number of bins to use for non-missing values.
Impact:
- Memory efficiency
- Training speed
- Feature resolution
Trade-offs:
- Lower values: Faster, less precise
- Higher values: More precise, more memory
Guidelines:
- Minimum: 2 bins
- Default: 255 bins (optimal)
- Maximum: 255 bins (uint8 limit)
WarmStart
boolWhen set to True, reuse the solution of the previous call to fit and add more estimators to the ensemble.
Functionality:
- Reuses previous model
- Adds more estimators
- Continues training
- Preserves learned patterns
Use cases:
- Online learning
- Iterative training
- Model updating
- Experimental tuning
Note: May affect convergence behavior
EarlyStopping
boolEnable validation-based training stop:
Operation:
- Monitors validation score
- Prevents overfitting
- Optimizes iterations
- Saves computation
Requirements:
- Validation fraction > 0
- n_iter_no_change > 0
- Sufficient training data
Best practices:
- Enable for large datasets
- Use with validation_fraction
- Monitor convergence pattern
Proportion (or absolute size) of training data to set aside as validation data for early stopping. If None, early stopping is done on the training data. Only used if early stopping is performed.
Usage:
- Early stopping validation
- Model monitoring
- Convergence checking
Guidelines:
- Small datasets: 0.1-0.15
- Medium datasets: 0.1 (default)
- Large datasets: 0.05-0.1
Considerations:
- Dataset size
- Validation stability
- Training data needs
Early stopping patience parameter:
Function:
- Defines stopping patience
- Controls training length
- Balances optimization
- Prevents premature stopping
Setting guidelines:
- Conservative: 15-20 iterations
- Standard: 10 iterations (default)
- Aggressive: 5-8 iterations
Note: Larger values ensure better convergence
Tol
f64Score improvement tolerance for early stopping:
Purpose:
- Defines meaningful improvement
- Controls convergence precision
- Affects training duration
Typical values:
- Strict: 1e-8 to 1e-7
- Standard: 1e-7 (default)
- Relaxed: 1e-6 to 1e-5
Impact:
- Smaller values: More precise, longer training
- Larger values: Faster convergence, less precise
RandomState
u64Random number generator seed:
Controls randomization in:
- Feature selection
- Sample bootstrapping
- Split point selection
- Early stopping splits
Importance:
- Reproducibility
- Debugging
- Result verification
- Experimental control
ClassWeight
enumClass weighting schemes:
Note: Affects all trees in ensemble
Equal class weights:
Properties:
- No bias adjustment
- Natural distributions
- Default behavior
- Fast computation
Inverse frequency weights:
Formula:
Properties:
- Handles imbalance
- Adjusts importance
- Fair to minorities
- Class-sensitive
Grid search parameters.
LearningRate
[f64, ...]Learning rate search space:
Search strategies:
- Logarithmic scale (recommended):
- Coarse: [0.01, 0.1, 1.0]
- Fine: [0.01, 0.03, 0.1, 0.3]
Optimization tips:
- Pair with max_iter
- Smaller values need more iterations
- Consider training time budget
Example ranges:
- Fast training: [0.1, 0.3]
- Balanced: [0.05, 0.1, 0.15]
- Precise: [0.01, 0.03, 0.05]
MaxIter
[u32, ...]Number of boosting iterations search space:
Search patterns:
- Basic range:
- [50, 100, 200] iterations
- Extended search:
- [100, 300, 500, 1000] iterations
Considerations:
- Dataset size and complexity
- Learning rate interaction
- Early stopping impact
- Computational resources
Formula guide:
- Base iterations ≈ 1/(learning_rate)
- Adjust for problem complexity
MaxLeafNodes
[u32, ...]Tree size exploration space:
Search strategies:
- Powers of 2 (common):
- [15, 31, 63, 127] nodes
- Linear increments:
- [20, 50, 100, 200] nodes
Performance impact:
- Memory usage scales linearly
- Training time correlation
- Model complexity control
Problem-based ranges:
- Simple: [15-31] nodes
- Medium: [31-127] nodes
- Complex: [127-511] nodes
MaxDepth
[u32, ...]Tree depth search range:
Search patterns:
- Conservative:
- [3, 5, 7] levels
- Extended:
- [4, 6, 8, 10] levels
Resource impact:
- Memory: O(2^depth)
- Training time: O(depth)
- Feature interactions: O(depth)
Guidelines:
- Start shallow (3-5)
- Increment gradually
- Monitor overfitting
- Consider max_leaf_nodes interaction
MinSamplesLeaf
[u32, ...]Minimum leaf size search space:
Search strategies:
- Small datasets:
- [5, 10, 20] samples
- Large datasets:
- [20, 50, 100] samples
Scaling considerations:
- Dataset size correlation
- Noise sensitivity
- Overfitting prevention
Selection guide:
- Base value ≈ sqrt(n_samples)
- Adjust for noise level
- Consider class distribution
L2Regularization
[f64, ...]L2 regularization strength search space:
Search patterns:
- Logarithmic scale:
- [0.0, 0.1, 1.0, 10.0]
- Fine-tuning:
- [0.01, 0.1, 0.3, 1.0]
Optimization focus:
- Overfitting control
- Model stability
- Prediction smoothness
Dataset considerations:
- Noise level
- Feature count
- Sample size
- Model complexity
MaxFeatures
[f64, ...]Feature fraction search space:
Search strategies:
- Standard range:
- [0.6, 0.8, 1.0]
- Extended search:
- [0.4, 0.6, 0.8, 1.0]
Performance impact:
- Training speed
- Tree diversity
- Feature utilization
Selection guide:
- High features: Lower fractions
- Few features: Higher fractions
- Consider feature importance spread
MaxBins
[u32, ...]Binning resolution search space:
Search patterns:
- Memory-conscious:
- [32, 64, 128, 255] bins
- Precision-focused:
- [128, 192, 255] bins
Trade-off analysis:
- Memory usage vs precision
- Training speed vs accuracy
- Data resolution needs
Guidelines:
- Start with lower values
- Increase if underfitting
- Monitor memory usage
WarmStart
[bool, ...]Warm start strategy evaluation:
Search options:
- [false]: Standard training
- [true, false]: Compare approaches
Use cases:
- Incremental learning
- Model extension
- Parameter sensitivity analysis
Evaluation metrics:
- Training stability
- Convergence behavior
- Resource utilization
ClassWeight
[enum, ...]Class weighting schemes:
Note: Affects all trees in ensemble
Equal class weights:
Properties:
- No bias adjustment
- Natural distributions
- Default behavior
- Fast computation
Inverse frequency weights:
Formula:
Properties:
- Handles imbalance
- Adjusts importance
- Fair to minorities
- Class-sensitive
EarlyStopping
boolEarly stopping strategy control:
Configuration purpose:
- Training efficiency
- Overfitting prevention
- Resource optimization
- Performance monitoring
Best practices:
- Enable for large datasets
- Use with validation_fraction
- Pair with n_iter_no_change
- Monitor convergence patterns
Validation set size control:
Selection guide:
- Small data: 0.15-0.20
- Medium data: 0.10 (default)
- Large data: 0.05-0.10
Considerations:
- Dataset size
- Validation stability
- Training data needs
- Early stopping requirements
Early stopping patience configuration:
Common ranges:
- Aggressive: 5-8 iterations
- Standard: 10 iterations
- Conservative: 15-20 iterations
Selection factors:
- Learning rate
- Dataset size
- Model complexity
- Convergence patterns
Tol
f64Improvement tolerance threshold:
Typical ranges:
- Strict: 1e-8 to 1e-7
- Standard: 1e-7 (default)
- Relaxed: 1e-6 to 1e-5
Impact factors:
- Convergence speed
- Training duration
- Score precision
- Resource usage
RandomState
u64Random seed for reproducibility:
Applications:
- Result reproducibility
- Parameter tuning
- Model comparison
- Debug scenarios
Best practices:
- Fix seed for development
- Vary for robustness checks
- Document for replication
RefitScore
enumPerformance evaluation metrics for classification:
Purpose:
- Model evaluation
- Ensemble selection
- Early stopping
- Performance tracking
Selection criteria:
- Problem objectives
- Class distribution
- Ensemble size
- Computation resources
Uses ensemble's built-in scoring:
Properties:
- Weighted accuracy metric
- Ensemble-aware scoring
- Fast computation
- Boosting-compatible
Best for:
- Standard problems
- Quick evaluation
- Initial testing
- Performance tracking
Standard classification accuracy:
Formula:
Properties:
- Range: [0, 1]
- Ensemble consensus
- Intuitive metric
- Equal error weights
Best for:
- Balanced datasets
- Equal error costs
- Simple evaluation
- Quick benchmarking
Class-normalized accuracy score:
Formula:
Properties:
- Range: [0, 1]
- Class-weighted
- Imbalance-robust
- Fair evaluation
Best for:
- Imbalanced data
- Varied class sizes
- Minority focus
- Fair assessment
Logarithmic loss (Cross-entropy):
Formula:
Properties:
- Range: [0, ∞)
- Probability-sensitive
- Boosting-optimal
- Confidence-aware
Best for:
- Probability estimation
- Boosting optimization
- Risk assessment
- Model calibration
Area Under ROC Curve:
Properties:
- Range: [0, 1]
- Ranking quality
- Threshold-invariant
- Ensemble-appropriate
Best for:
- Binary problems
- Ranking tasks
- Score calibration
- Model comparison
Note: Extended to multi-class via averaging
Split
oneofStandard train-test split configuration optimized for general classification tasks.
Configuration:
- Test size: 20% (0.2)
- Random seed: 98
- Shuffling: Enabled
- Stratification: Based on target distribution
Advantages:
- Preserves class distribution
- Provides reliable validation
- Suitable for most datasets
Best for:
- Medium to large datasets
- Independent observations
- Initial model evaluation
Splitting uses the ShuffleSplit strategy or StratifiedShuffleSplit strategy depending on the field stratified
. Note: If shuffle is false then stratified must be false.
Configurable train-test split parameters for specialized requirements. Allows fine-tuning of data division strategy for specific use cases or constraints.
Use cases:
- Time series data
- Grouped observations
- Specific train/test ratios
- Custom validation schemes
RandomState
u64Random seed for reproducible splits. Ensures:
- Consistent train/test sets
- Reproducible experiments
- Comparable model evaluations
Same seed guarantees identical splits across runs.
Shuffle
boolData shuffling before splitting. Effects:
- true: Randomizes order, better for i.i.d. data
- false: Maintains order, important for time series
When to disable:
- Time dependent data
- Sequential patterns
- Grouped observations
TrainSize
f64Proportion of data for training. Considerations:
- Larger (e.g., 0.8-0.9): Better model learning
- Smaller (e.g., 0.5-0.7): Better validation
Common splits:
- 0.8: Standard (80/20 split)
- 0.7: More validation emphasis
- 0.9: More training emphasis
Stratified
boolMaintain class distribution in splits. Important when:
- Classes are imbalanced
- Small classes present
- Representative splits needed
Requirements:
- Classification tasks only
- Cannot use with shuffle=false
- Sufficient samples per class
Cv
oneofStandard cross-validation configuration using stratified 3-fold splitting.
Configuration:
- Folds: 3
- Method: StratifiedKFold
- Stratification: Preserves class proportions
Advantages:
- Balanced evaluation
- Reasonable computation time
- Good for medium-sized datasets
Limitations:
- May be insufficient for small datasets
- Higher variance than larger fold counts
- May miss some data patterns
Configurable stratified k-fold cross-validation for specific validation requirements.
Features:
- Adjustable fold count with
NFolds
determining the number of splits. - Stratified sampling
- Preserved class distributions
Use cases:
- Small datasets (more folds)
- Large datasets (fewer folds)
- Detailed model evaluation
- Robust performance estimation
NFolds
u32Number of cross-validation folds. Guidelines:
- 3-5: Large datasets, faster training
- 5-10: Standard choice, good balance
- 10+: Small datasets, thorough evaluation
Trade-offs:
- More folds: Better evaluation, slower training
- Fewer folds: Faster training, higher variance
Must be at least 2.
K-fold cross-validation without stratification. Divides data into k consecutive folds for iterative validation.
Process:
- Splits data into k equal parts
- Each fold serves as validation once
- Remaining k-1 folds form training set
Use cases:
- Regression problems
- Large, balanced datasets
- When stratification unnecessary
- Continuous target variables
Limitations:
- May not preserve class distributions
- Less suitable for imbalanced data
- Can create biased splits with ordered data
NSplits
u32Number of folds for cross-validation. Selection guide: Recommended values:
- 5: Standard choice (default)
- 3: Large datasets/quick evaluation
- 10: Thorough evaluation/smaller datasets
Trade-offs:
- Higher values: More thorough, computationally expensive
- Lower values: Faster, potentially higher variance
Must be at least 2 for valid cross-validation.
RandomState
u64Random seed for fold generation when shuffling. Important for:
- Reproducible results
- Consistent fold assignments
- Benchmark comparisons
- Debugging and validation
Set specific value for reproducibility across runs.
Shuffle
boolWhether to shuffle data before splitting into folds. Effects:
- true: Randomized fold composition (recommended)
- false: Sequential splitting
Enable when:
- Data may have ordering
- Better fold independence needed
Disable for:
- Time series data
- Ordered observations
Stratified K-fold cross-validation maintaining class proportions across folds.
Key features:
- Preserves class distribution in each fold
- Handles imbalanced datasets
- Ensures representative splits
Best for:
- Classification problems
- Imbalanced class distributions
- When class proportions matter
Requirements:
- Classification tasks only
- Sufficient samples per class
- Categorical target variable
NSplits
u32Number of stratified folds. Guidelines: Typical values:
- 5: Standard for most cases
- 3: Quick evaluation/large datasets
- 10: Detailed evaluation/smaller datasets
Considerations:
- Must allow sufficient samples per class per fold
- Balance between stability and computation time
- Consider smallest class size when choosing
RandomState
u64Seed for reproducible stratified splits. Ensures:
- Consistent fold assignments
- Reproducible results
- Comparable experiments
- Systematic validation
Fixed seed guarantees identical stratified splits.
Shuffle
boolData shuffling before stratified splitting. Impact:
- true: Randomizes while maintaining stratification
- false: Maintains data order within strata
Use cases:
- true: Independent observations
- false: Grouped or sequential data
Class proportions maintained regardless of setting.
Random permutation cross-validator with independent sampling.
Characteristics:
- Random sampling for each split
- Independent train/test sets
- More flexible than K-fold
- Can have overlapping test sets
Advantages:
- Control over test size
- Fresh splits each iteration
- Good for large datasets
Limitations:
- Some samples might never be tested
- Others might be tested multiple times
- No guarantee of complete coverage
NSplits
u32Number of random splits to perform. Consider: Common values:
- 5: Standard evaluation
- 10: More thorough assessment
- 3: Quick estimates
Trade-offs:
- More splits: Better estimation, longer runtime
- Fewer splits: Faster, less stable estimates
Balance between computation and stability.
RandomState
u64Random seed for reproducible shuffling. Controls:
- Split randomization
- Sample selection
- Result reproducibility
Important for:
- Debugging
- Comparative studies
- Result verification
TestSize
f64Proportion of samples for test set. Guidelines: Common ratios:
- 0.2: Standard (80/20 split)
- 0.25: More validation emphasis
- 0.1: More training data
Considerations:
- Dataset size
- Model complexity
- Validation requirements
It must be between 0.0 and 1.0.
Stratified random permutation cross-validator combining shuffle-split with stratification.
Features:
- Maintains class proportions
- Random sampling within strata
- Independent splits
- Flexible test size
Ideal for:
- Imbalanced datasets
- Large-scale problems
- When class distributions matter
- Flexible validation schemes
NSplits
u32Number of stratified random splits. Guidelines: Recommended values:
- 5: Standard evaluation
- 10: Detailed analysis
- 3: Quick assessment
Consider:
- Sample size per class
- Computational resources
- Stability requirements
RandomState
u64Seed for reproducible stratified sampling. Ensures:
- Consistent class proportions
- Reproducible splits
- Comparable experiments
Critical for:
- Benchmarking
- Research studies
- Quality assurance
TestSize
f64Fraction of samples for stratified test set. Best practices: Common splits:
- 0.2: Balanced evaluation
- 0.3: More thorough testing
- 0.15: Preserve training size
Consider:
- Minority class size
- Overall dataset size
- Validation objectives
It must be between 0.0 and 1.0.
Time Series cross-validator. Provides train/test indices to split time series data samples that are observed at fixed time intervals, in train/test sets. It is a variation of k-fold which returns first k
folds as train set and the k + 1
th fold as test set. Note that unlike standard cross-validation methods, successive training sets are supersets of those that come before them. Also, it adds all surplus data to the first training partition, which is always used to train the model.
Key features:
- Maintains temporal dependence
- Expanding window approach
- Forward-chaining splits
- No future data leakage
Use cases:
- Sequential data
- Financial forecasting
- Temporal predictions
- Time-dependent patterns
Note: Training sets are supersets of previous iterations.
NSplits
u32Number of temporal splits. Considerations: Typical values:
- 5: Standard forward chaining
- 3: Limited historical data
- 10: Long time series
Impact:
- Affects training window growth
- Determines validation points
- Influences computational load
MaxTrainSize
u64Maximum size of training set. Should be strictly less than the number of samples. Applications:
- 0: Use all available past data
- >0: Rolling window of fixed size
Use cases:
- Limit historical relevance
- Control computational cost
- Handle concept drift
- Memory constraints
TestSize
u64Number of samples in each test set. When 0:
- Auto-calculated as n_samples/(n_splits+1)
- Ensures equal-sized test sets
Considerations:
- Forecast horizon
- Validation requirements
- Available future data
Gap
u64Number of samples to exclude from the end of each train set before the test set.Gap between train and test sets. Uses:
- Avoid data leakage
- Model forecast lag
- Buffer periods
Common scenarios:
- 0: Continuous prediction
- >0: Forward gap for realistic evaluation
- Match business forecasting needs