SKLearner Home | About | Contact | Examples

Configure SVR "verbose" Parameter

The verbose parameter in scikit-learn’s SVR class controls the verbosity of output during the training process.

Support Vector Regression (SVR) is a popular algorithm for regression tasks. The verbose parameter determines how much information is printed during training.

The verbose parameter accepts integer values. Setting verbose=0 (default) suppresses all output, verbose=1 provides moderate output to track progress, and verbose>1 gives detailed output, which can be helpful for debugging.

While higher verbosity can be useful for monitoring the training process, it slightly increases the runtime due to the overhead of printing output. However, the verbose setting does not affect the model’s performance, only the amount of information displayed during training.

from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from sklearn.svm import SVR
from sklearn.metrics import mean_squared_error
import time

# 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]
train_times = []

for v in verbose_values:
    start_time = time.time()
    svr = SVR(verbose=v)
    svr.fit(X_train, y_train)
    end_time = time.time()
    train_times.append(end_time - start_time)

    y_pred = svr.predict(X_test)
    mse = mean_squared_error(y_test, y_pred)
    print(f"verbose={v}, Training time: {train_times[-1]:.3f}s, MSE: {mse:.3f}")

This example produces an output similar to:

verbose=0, Training time: 0.023s, MSE: 12758.146
[LibSVM]*
optimization finished, #iter = 402
obj = -77820.383529, rho = -2.862419
nSV = 799, nBSV = 797
verbose=1, Training time: 0.022s, MSE: 12758.146
[LibSVM]*
optimization finished, #iter = 402
obj = -77820.383529, rho = -2.862419
nSV = 799, nBSV = 797
verbose=2, Training time: 0.023s, MSE: 12758.146

The key steps in this example are:

  1. Generate a synthetic regression dataset with noise
  2. Split the data into train and test sets
  3. Train SVR models with different verbose values and record training times
  4. Evaluate the mean squared error of each model on the test set

Some tips and considerations for setting verbose:



See Also