SKLearner Home | About | Contact | Examples

Configure VotingRegressor "verbose" Parameter

The verbose parameter in scikit-learn’s VotingRegressor controls the level of output during fitting and prediction.

VotingRegressor is an ensemble method that combines predictions from multiple base regressors to produce a final prediction. The verbose parameter determines how much information is displayed during the model’s operations.

Higher verbose values provide more detailed output, which can be useful for debugging or monitoring progress, especially with large datasets or complex models.

The default value for verbose is 0, which means no output is produced. Common values are 0 (no output), 1 (some output), and 2 (detailed output).

from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from sklearn.ensemble import VotingRegressor
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.svm import SVR
from sklearn.metrics import mean_squared_error

# 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)

# Define base models
base_models = [
    ('lr', LinearRegression()),
    ('rf', RandomForestRegressor(n_estimators=10, random_state=42)),
    ('svr', SVR(kernel='rbf'))
]

# Train with different verbose values
verbose_values = [0, 1, 2]

for verbose in verbose_values:
    vr = VotingRegressor(estimators=base_models, verbose=verbose)
    vr.fit(X_train, y_train)
    y_pred = vr.predict(X_test)
    mse = mean_squared_error(y_test, y_pred)
    print(f"verbose={verbose}, MSE: {mse:.3f}")

Running the example gives an output like:

verbose=0, MSE: 2652.396
[Voting] ....................... (1 of 3) Processing lr, total=   0.0s
[Voting] ....................... (2 of 3) Processing rf, total=   0.1s
[Voting] ...................... (3 of 3) Processing svr, total=   0.0s
verbose=1, MSE: 2652.396
[Voting] ....................... (1 of 3) Processing lr, total=   0.0s
[Voting] ....................... (2 of 3) Processing rf, total=   0.1s
[Voting] ...................... (3 of 3) Processing svr, total=   0.0s
verbose=2, MSE: 2652.396

The key steps in this example are:

  1. Generate a synthetic regression dataset
  2. Split the data into train and test sets
  3. Define base models for the VotingRegressor
  4. Train VotingRegressor models with different verbose values
  5. Evaluate the mean squared error of each model on the test set

Some tips for using the verbose parameter:

Issues to consider:



See Also