machine learning
python
sklearn
LinearSVC
decision probabilities

SKLearn how to get decision probabilities for LinearSVC classifier

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

LinearSVC is fast and effective for linear classification, especially on high-dimensional sparse data such as text features. A common surprise is that it does not implement predict_proba, so you cannot ask it for calibrated class probabilities directly. This article explains what LinearSVC does provide, how to turn its scores into probabilities, and when another model is a better fit.

What LinearSVC Returns

LinearSVC exposes a decision function, not probabilities. The decision score tells you how far a sample is from the separating hyperplane.

That score is useful for ranking and margin-based decisions, but it is not the same as a probability. A value of 2.0 does not mean 200 percent confidence, and a value near 0 does not automatically correspond to 50 percent probability without calibration.

Inspect the Decision Function

Here is a minimal text classification example using LinearSVC.

python
1from sklearn.feature_extraction.text import TfidfVectorizer
2from sklearn.pipeline import make_pipeline
3from sklearn.svm import LinearSVC
4
5X_train = [
6    "great product and fast shipping",
7    "excellent quality and works well",
8    "terrible support and broken item",
9    "waste of money and poor quality",
10]
11y_train = [1, 1, 0, 0]
12
13model = make_pipeline(
14    TfidfVectorizer(),
15    LinearSVC(random_state=42)
16)
17
18model.fit(X_train, y_train)
19
20scores = model.decision_function([
21    "great quality",
22    "poor support",
23])
24
25print(scores)

Positive scores lean toward class 1, negative scores toward class 0. The larger the absolute value, the farther the example is from the boundary.

Use Calibration to Get Probabilities

If you need proper probabilities, wrap LinearSVC in CalibratedClassifierCV. This fits a calibration model on top of the decision scores.

python
1from sklearn.calibration import CalibratedClassifierCV
2from sklearn.feature_extraction.text import TfidfVectorizer
3from sklearn.pipeline import Pipeline
4from sklearn.svm import LinearSVC
5
6X_train = [
7    "great product and fast shipping",
8    "excellent quality and works well",
9    "terrible support and broken item",
10    "waste of money and poor quality",
11    "very satisfied with this purchase",
12    "refund requested after it failed",
13]
14y_train = [1, 1, 0, 0, 1, 0]
15
16pipeline = Pipeline([
17    ("tfidf", TfidfVectorizer()),
18    ("svc", CalibratedClassifierCV(
19        estimator=LinearSVC(random_state=42),
20        method="sigmoid",
21        cv=3,
22    )),
23])
24
25pipeline.fit(X_train, y_train)
26
27proba = pipeline.predict_proba([
28    "excellent support and quality",
29    "broken and disappointing",
30])
31
32print(proba)

Each row contains calibrated probabilities for the classes. In binary classification, column 1 is usually the positive-class probability.

Why Calibration Is Needed

The SVM margin is optimized for classification accuracy, not probability estimation. Calibration learns a mapping from decision scores to probabilities using held-out data.

In scikit-learn, the common calibration methods are:

  • 'sigmoid, which is often a good default'
  • 'isotonic, which is more flexible but needs more data'

If you care about thresholds, ranking, or risk scoring, calibration is usually the correct solution.

Multi-Class Behavior

For multi-class problems, LinearSVC uses one-vs-rest internally. Calibration still works, but probability quality depends on data size and class balance.

python
1from sklearn.datasets import load_iris
2from sklearn.model_selection import train_test_split
3from sklearn.calibration import CalibratedClassifierCV
4from sklearn.svm import LinearSVC
5
6X, y = load_iris(return_X_y=True)
7X_train, X_test, y_train, y_test = train_test_split(
8    X, y, test_size=0.25, random_state=42, stratify=y
9)
10
11clf = CalibratedClassifierCV(
12    estimator=LinearSVC(random_state=42),
13    method="sigmoid",
14    cv=3,
15)
16clf.fit(X_train, y_train)
17
18print(clf.predict_proba(X_test[:3]))

The output rows sum to 1.0, which makes them usable in downstream probability-based decisions.

When to Choose a Different Model

If probability output is central to the problem, another model may be simpler:

  • 'LogisticRegression gives probabilities directly and often works very well on linear problems.'
  • 'SVC(probability=True) provides probabilities, though it can be slower than LinearSVC.'
  • Tree ensembles can provide probabilities too, but calibration may still improve them.

Do not force LinearSVC into a probability role if a different classifier matches the requirement more naturally.

Validate the Probabilities

Calibrated probabilities are only useful if they are actually well calibrated on unseen data. Check this on a validation split, not just the training data.

Metrics and tools that help:

  • log loss
  • Brier score
  • calibration curves

That validation step matters more than simply having a predict_proba method available.

Common Pitfalls

  • Expecting LinearSVC to implement predict_proba directly.
  • Treating raw decision scores as probabilities.
  • Calibrating on too little data and assuming the output is trustworthy.
  • Forgetting that calibration adds extra training cost.
  • Using LinearSVC when LogisticRegression would better match the problem requirements.

Summary

  • 'LinearSVC provides decision scores, not native probabilities.'
  • Use CalibratedClassifierCV when you need probability estimates.
  • Choose sigmoid first unless you have enough data to justify isotonic.
  • Validate calibrated probabilities on held-out data before using them operationally.
  • If probabilities are the main goal, consider a classifier that supports them directly.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.