SKLearner Home | About | Contact | Examples

Configure SVC "break_ties" Parameter

The SVC class in scikit-learn is a powerful tool for Support Vector Machine classification. It’s particularly useful when dealing with complex, nonlinear decision boundaries.

The break_ties parameter in SVC determines how to handle cases where multiple classes have equal decision function values. When break_ties is False (default), the class with the smallest index is returned. Setting it to True breaks ties randomly.

This example demonstrates how to configure the break_ties parameter and its effect on model performance, particularly in scenarios with closely situated classes.

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 with close classes
X, y = make_classification(n_samples=1000, n_classes=3, n_features=10,
                           n_informative=5, n_redundant=0, n_clusters_per_class=1,
                           class_sep=0.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 break_ties values
for break_ties in [False, True]:
    svc = SVC(kernel='linear', C=1, break_ties=break_ties, random_state=42)
    svc.fit(X_train, y_train)
    y_pred = svc.predict(X_test)
    accuracy = accuracy_score(y_test, y_pred)
    print(f"break_ties={break_ties}, Accuracy: {accuracy:.3f}")

Running the example gives an output like:

break_ties=False, Accuracy: 0.805
break_ties=True, Accuracy: 0.795

The key steps in this example are:

  1. Generate a synthetic multiclass classification dataset with close classes
  2. Split the data into train and test sets
  3. Train SVC models with break_ties set to False and True
  4. Evaluate the accuracy of each model on the test set

Some tips and heuristics for setting break_ties:

Issues to consider:



See Also