SKLearner Home | About | Contact | Examples

Configure SVC "verbose" Parameter

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

Setting verbose to a positive integer enables printing of convergence information for each iteration of the optimization algorithm. This output can be useful for tracking the progress and diagnosing issues.

By default, verbose is set to 0, which disables any printed output during training.

In practice, verbose is usually set to either 0 (no output) or 1 (print optimization info). Higher values of verbose will print additional details about the optimization process.

from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score

# Generate synthetic dataset
X, y = make_classification(n_samples=1000, n_classes=2, n_features=10,
                           n_informative=5, 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]
accuracies = []

for v in verbose_values:
    print(f"\nTraining with verbose={v}:")
    svc = SVC(verbose=v, random_state=42)
    svc.fit(X_train, y_train)
    y_pred = svc.predict(X_test)
    accuracy = accuracy_score(y_test, y_pred)
    accuracies.append(accuracy)
    print(f"Accuracy: {accuracy:.3f}")

Running the example gives an output like:


Training with verbose=0:
Accuracy: 0.920

Training with verbose=1:
[LibSVM]*
optimization finished, #iter = 485
obj = -213.693512, rho = 0.353145
nSV = 306, nBSV = 236
Total nSV = 306
Accuracy: 0.920

The key steps in this example are:

  1. Generate a synthetic binary classification dataset
  2. Split the data into train and test sets
  3. Train SVC models with different verbose values
  4. Print the optimization output when verbose is enabled
  5. Evaluate the accuracy of each model on the test set

Some tips for using the verbose parameter:

Keep in mind that enabling verbose output will slow down the training process, as printing information takes additional time.



See Also