The verbose
parameter in scikit-learn’s HistGradientBoostingRegressor
controls the level of output during model training.
HistGradientBoostingRegressor
is a gradient boosting algorithm that uses histogram-based decision trees. It’s known for its efficiency and performance on large datasets.
The verbose
parameter determines how much information is printed during the fitting process. It can be set to 0 (no output), 1 (some output), or greater values for more detailed information.
By default, verbose
is set to 0, which means no output is produced during training. Common values are 0 for silent operation and 1 for basic progress information.
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from sklearn.ensemble import HistGradientBoostingRegressor
from sklearn.metrics import mean_squared_error
import numpy as np
# Generate synthetic dataset
X, y = make_regression(n_samples=1000, n_features=10, noise=0.1, random_state=42)
# Split into train and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Train with different verbose values
verbose_values = [0, 1, 2]
for v in verbose_values:
print(f"\nTraining with verbose={v}")
hgbr = HistGradientBoostingRegressor(max_iter=100, random_state=42, verbose=v)
hgbr.fit(X_train, y_train)
y_pred = hgbr.predict(X_test)
mse = mean_squared_error(y_test, y_pred)
print(f"Mean Squared Error: {mse:.4f}")
Running the example gives an output like:
Training with verbose=0
Mean Squared Error: 1023.0742
Training with verbose=1
Binning 0.000 GB of training data: 0.006 s
Fitting gradient boosted rounds:
[1/100] 1 tree, 31 leaves, max depth = 7, in 0.003s
[2/100] 1 tree, 31 leaves, max depth = 7, in 0.003s
[3/100] 1 tree, 31 leaves, max depth = 7, in 0.002s
[4/100] 1 tree, 29 leaves, max depth = 7, in 0.002s
[5/100] 1 tree, 30 leaves, max depth = 7, in 0.002s
[6/100] 1 tree, 31 leaves, max depth = 7, in 0.002s
[7/100] 1 tree, 31 leaves, max depth = 8, in 0.004s
[8/100] 1 tree, 31 leaves, max depth = 7, in 0.002s
[9/100] 1 tree, 30 leaves, max depth = 10, in 0.002s
[10/100] 1 tree, 31 leaves, max depth = 10, in 0.002s
[11/100] 1 tree, 31 leaves, max depth = 8, in 0.002s
[12/100] 1 tree, 31 leaves, max depth = 8, in 0.002s
[13/100] 1 tree, 31 leaves, max depth = 9, in 0.002s
[14/100] 1 tree, 30 leaves, max depth = 9, in 0.003s
[15/100] 1 tree, 30 leaves, max depth = 9, in 0.002s
[16/100] 1 tree, 30 leaves, max depth = 9, in 0.002s
[17/100] 1 tree, 31 leaves, max depth = 10, in 0.002s
[18/100] 1 tree, 31 leaves, max depth = 10, in 0.002s
[19/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[20/100] 1 tree, 31 leaves, max depth = 9, in 0.002s
[21/100] 1 tree, 31 leaves, max depth = 14, in 0.004s
[22/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[23/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[24/100] 1 tree, 31 leaves, max depth = 11, in 0.002s
[25/100] 1 tree, 31 leaves, max depth = 11, in 0.002s
[26/100] 1 tree, 31 leaves, max depth = 13, in 0.002s
[27/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[28/100] 1 tree, 31 leaves, max depth = 12, in 0.004s
[29/100] 1 tree, 30 leaves, max depth = 15, in 0.002s
[30/100] 1 tree, 31 leaves, max depth = 12, in 0.003s
[31/100] 1 tree, 31 leaves, max depth = 10, in 0.002s
[32/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[33/100] 1 tree, 31 leaves, max depth = 16, in 0.002s
[34/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[35/100] 1 tree, 30 leaves, max depth = 13, in 0.004s
[36/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[37/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[38/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[39/100] 1 tree, 31 leaves, max depth = 13, in 0.001s
[40/100] 1 tree, 30 leaves, max depth = 15, in 0.002s
[41/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[42/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[43/100] 1 tree, 31 leaves, max depth = 13, in 0.003s
[44/100] 1 tree, 30 leaves, max depth = 15, in 0.002s
[45/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[46/100] 1 tree, 31 leaves, max depth = 13, in 0.002s
[47/100] 1 tree, 31 leaves, max depth = 15, in 0.001s
[48/100] 1 tree, 31 leaves, max depth = 15, in 0.001s
[49/100] 1 tree, 31 leaves, max depth = 17, in 0.002s
[50/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[51/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[52/100] 1 tree, 31 leaves, max depth = 12, in 0.004s
[53/100] 1 tree, 31 leaves, max depth = 13, in 0.002s
[54/100] 1 tree, 31 leaves, max depth = 15, in 0.003s
[55/100] 1 tree, 30 leaves, max depth = 14, in 0.002s
[56/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[57/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[58/100] 1 tree, 31 leaves, max depth = 13, in 0.003s
[59/100] 1 tree, 30 leaves, max depth = 13, in 0.003s
[60/100] 1 tree, 31 leaves, max depth = 14, in 0.003s
[61/100] 1 tree, 31 leaves, max depth = 12, in 0.003s
[62/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[63/100] 1 tree, 29 leaves, max depth = 11, in 0.002s
[64/100] 1 tree, 31 leaves, max depth = 14, in 0.004s
[65/100] 1 tree, 30 leaves, max depth = 11, in 0.003s
[66/100] 1 tree, 30 leaves, max depth = 17, in 0.003s
[67/100] 1 tree, 31 leaves, max depth = 13, in 0.002s
[68/100] 1 tree, 30 leaves, max depth = 11, in 0.002s
[69/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[70/100] 1 tree, 31 leaves, max depth = 14, in 0.005s
[71/100] 1 tree, 31 leaves, max depth = 17, in 0.003s
[72/100] 1 tree, 30 leaves, max depth = 12, in 0.002s
[73/100] 1 tree, 30 leaves, max depth = 11, in 0.002s
[74/100] 1 tree, 31 leaves, max depth = 13, in 0.002s
[75/100] 1 tree, 30 leaves, max depth = 12, in 0.003s
[76/100] 1 tree, 31 leaves, max depth = 19, in 0.005s
[77/100] 1 tree, 31 leaves, max depth = 12, in 0.003s
[78/100] 1 tree, 31 leaves, max depth = 16, in 0.003s
[79/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[80/100] 1 tree, 31 leaves, max depth = 16, in 0.002s
[81/100] 1 tree, 31 leaves, max depth = 13, in 0.002s
[82/100] 1 tree, 31 leaves, max depth = 18, in 0.004s
[83/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[84/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[85/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[86/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[87/100] 1 tree, 31 leaves, max depth = 21, in 0.002s
[88/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[89/100] 1 tree, 30 leaves, max depth = 13, in 0.003s
[90/100] 1 tree, 31 leaves, max depth = 14, in 0.003s
[91/100] 1 tree, 31 leaves, max depth = 18, in 0.002s
[92/100] 1 tree, 31 leaves, max depth = 18, in 0.002s
[93/100] 1 tree, 30 leaves, max depth = 20, in 0.002s
[94/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[95/100] 1 tree, 31 leaves, max depth = 10, in 0.002s
[96/100] 1 tree, 29 leaves, max depth = 16, in 0.003s
[97/100] 1 tree, 31 leaves, max depth = 24, in 0.003s
[98/100] 1 tree, 31 leaves, max depth = 17, in 0.003s
[99/100] 1 tree, 30 leaves, max depth = 13, in 0.002s
[100/100] 1 tree, 31 leaves, max depth = 11, in 0.002s
Fit 100 trees in 0.250 s, (3074 total leaves)
Time spent computing histograms: 0.044s
Time spent finding best splits: 0.034s
Time spent applying splits: 0.066s
Time spent predicting: 0.005s
Mean Squared Error: 1023.0742
Training with verbose=2
Binning 0.000 GB of training data: 0.007 s
Fitting gradient boosted rounds:
[1/100] 1 tree, 31 leaves, max depth = 7, in 0.002s
[2/100] 1 tree, 31 leaves, max depth = 7, in 0.002s
[3/100] 1 tree, 31 leaves, max depth = 7, in 0.002s
[4/100] 1 tree, 29 leaves, max depth = 7, in 0.002s
[5/100] 1 tree, 30 leaves, max depth = 7, in 0.002s
[6/100] 1 tree, 31 leaves, max depth = 7, in 0.004s
[7/100] 1 tree, 31 leaves, max depth = 8, in 0.003s
[8/100] 1 tree, 31 leaves, max depth = 7, in 0.003s
[9/100] 1 tree, 30 leaves, max depth = 10, in 0.002s
[10/100] 1 tree, 31 leaves, max depth = 10, in 0.002s
[11/100] 1 tree, 31 leaves, max depth = 8, in 0.002s
[12/100] 1 tree, 31 leaves, max depth = 8, in 0.003s
[13/100] 1 tree, 31 leaves, max depth = 9, in 0.003s
[14/100] 1 tree, 30 leaves, max depth = 9, in 0.002s
[15/100] 1 tree, 30 leaves, max depth = 9, in 0.002s
[16/100] 1 tree, 30 leaves, max depth = 9, in 0.002s
[17/100] 1 tree, 31 leaves, max depth = 10, in 0.002s
[18/100] 1 tree, 31 leaves, max depth = 10, in 0.002s
[19/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[20/100] 1 tree, 31 leaves, max depth = 9, in 0.004s
[21/100] 1 tree, 31 leaves, max depth = 14, in 0.003s
[22/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[23/100] 1 tree, 31 leaves, max depth = 12, in 0.003s
[24/100] 1 tree, 31 leaves, max depth = 11, in 0.003s
[25/100] 1 tree, 31 leaves, max depth = 11, in 0.004s
[26/100] 1 tree, 31 leaves, max depth = 13, in 0.002s
[27/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[28/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[29/100] 1 tree, 30 leaves, max depth = 15, in 0.002s
[30/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[31/100] 1 tree, 31 leaves, max depth = 10, in 0.002s
[32/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[33/100] 1 tree, 31 leaves, max depth = 16, in 0.004s
[34/100] 1 tree, 31 leaves, max depth = 15, in 0.003s
[35/100] 1 tree, 30 leaves, max depth = 13, in 0.002s
[36/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[37/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[38/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[39/100] 1 tree, 31 leaves, max depth = 13, in 0.005s
[40/100] 1 tree, 30 leaves, max depth = 15, in 0.002s
[41/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[42/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[43/100] 1 tree, 31 leaves, max depth = 13, in 0.002s
[44/100] 1 tree, 30 leaves, max depth = 15, in 0.002s
[45/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[46/100] 1 tree, 31 leaves, max depth = 13, in 0.004s
[47/100] 1 tree, 31 leaves, max depth = 15, in 0.003s
[48/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[49/100] 1 tree, 31 leaves, max depth = 17, in 0.003s
[50/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[51/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[52/100] 1 tree, 31 leaves, max depth = 12, in 0.004s
[53/100] 1 tree, 31 leaves, max depth = 13, in 0.002s
[54/100] 1 tree, 31 leaves, max depth = 15, in 0.003s
[55/100] 1 tree, 30 leaves, max depth = 14, in 0.002s
[56/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[57/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[58/100] 1 tree, 31 leaves, max depth = 13, in 0.002s
[59/100] 1 tree, 30 leaves, max depth = 13, in 0.004s
[60/100] 1 tree, 31 leaves, max depth = 14, in 0.003s
[61/100] 1 tree, 31 leaves, max depth = 12, in 0.003s
[62/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[63/100] 1 tree, 29 leaves, max depth = 11, in 0.002s
[64/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[65/100] 1 tree, 30 leaves, max depth = 11, in 0.004s
[66/100] 1 tree, 30 leaves, max depth = 17, in 0.002s
[67/100] 1 tree, 31 leaves, max depth = 13, in 0.003s
[68/100] 1 tree, 30 leaves, max depth = 11, in 0.002s
[69/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[70/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[71/100] 1 tree, 31 leaves, max depth = 17, in 0.002s
[72/100] 1 tree, 30 leaves, max depth = 12, in 0.004s
[73/100] 1 tree, 30 leaves, max depth = 11, in 0.002s
[74/100] 1 tree, 31 leaves, max depth = 13, in 0.003s
[75/100] 1 tree, 30 leaves, max depth = 12, in 0.002s
[76/100] 1 tree, 31 leaves, max depth = 19, in 0.002s
[77/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[78/100] 1 tree, 31 leaves, max depth = 16, in 0.003s
[79/100] 1 tree, 31 leaves, max depth = 12, in 0.003s
[80/100] 1 tree, 31 leaves, max depth = 16, in 0.002s
[81/100] 1 tree, 31 leaves, max depth = 13, in 0.003s
[82/100] 1 tree, 31 leaves, max depth = 18, in 0.002s
[83/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[84/100] 1 tree, 31 leaves, max depth = 15, in 0.002s
[85/100] 1 tree, 31 leaves, max depth = 14, in 0.004s
[86/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[87/100] 1 tree, 31 leaves, max depth = 21, in 0.002s
[88/100] 1 tree, 31 leaves, max depth = 12, in 0.003s
[89/100] 1 tree, 30 leaves, max depth = 13, in 0.002s
[90/100] 1 tree, 31 leaves, max depth = 14, in 0.002s
[91/100] 1 tree, 31 leaves, max depth = 18, in 0.003s
[92/100] 1 tree, 31 leaves, max depth = 18, in 0.003s
[93/100] 1 tree, 30 leaves, max depth = 20, in 0.002s
[94/100] 1 tree, 31 leaves, max depth = 12, in 0.002s
[95/100] 1 tree, 31 leaves, max depth = 10, in 0.002s
[96/100] 1 tree, 29 leaves, max depth = 16, in 0.002s
[97/100] 1 tree, 31 leaves, max depth = 24, in 0.002s
[98/100] 1 tree, 31 leaves, max depth = 17, in 0.003s
[99/100] 1 tree, 30 leaves, max depth = 13, in 0.002s
[100/100] 1 tree, 31 leaves, max depth = 11, in 0.002s
Fit 100 trees in 0.259 s, (3074 total leaves)
Time spent computing histograms: 0.043s
Time spent finding best splits: 0.037s
Time spent applying splits: 0.065s
Time spent predicting: 0.004s
Mean Squared Error: 1023.0742
The key steps in this example are:
- Generate a synthetic regression dataset
- Split the data into train and test sets
- Train
HistGradientBoostingRegressor
models with differentverbose
values - Evaluate the mean squared error of each model on the test set
Tips for using the verbose
parameter:
- Use
verbose=0
for silent operation in production environments - Set
verbose=1
for basic progress information during development - Higher values of
verbose
provide more detailed output, useful for debugging
Issues to consider:
- Verbose output can slow down training slightly, especially with higher values
- In larger datasets or with more iterations, verbose output can be very long
- Verbose output is particularly useful when tuning hyperparameters or debugging model performance issues