Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Class

LinearSVC

LinearSVC is a linear support-vector classifier implemented with liblinear. It supports dense and sparse inputs, flexible penalties and losses, and one-vs-the-rest multiclass classification.

How it works

LinearSVC learns a linear decision boundary for classification using liblinear. It supports dense or sparse data and handles multiple classes with one-vs-the-rest training.

Syntax

class sklearn.svm.LinearSVC(*, penalty='l2', loss='squared_hinge', dual='auto', tol=0.0001, C=1.0, multi_class='ovr', fit_intercept=True, intercept_scaling=1, class_weight=None, verbose=0, random_state=None, max_iter=1000)

Parameters

NameTypeDescription
penaltystr, default='l2'Selects the penalty type: 'l1' or 'l2'.
lossstr, default='squared_hinge'Chooses 'hinge' or 'squared_hinge' loss.
dualbool or 'auto', default='auto'Whether to solve the dual optimization problem; 'auto' chooses automatically.
tolfloat, default=1e-4Tolerance for stopping criterion.
Cfloat, default=1.0Regularization parameter; smaller values mean stronger regularization.
multi_classstr, default='ovr'Multiclass strategy: 'ovr' or 'crammer_singer'.
fit_interceptbool, default=TrueWhether to fit the intercept.
intercept_scalingfloat, default=1Scaling applied to the synthetic intercept feature.
class_weightdict, 'balanced', or None, default=NoneClass weights, or 'balanced' to derive them from class frequencies.
verboseint, default=0Verbosity level.
random_stateint, RandomState instance, or None, default=NoneSeed controlling solver randomness.
max_iterint, default=1000Maximum number of solver iterations.

Returns

A fitted LinearSVC estimator with learned coefficients and intercept; prediction methods return class labels or decision scores.

Key points

  • It provides a linear SVM alternative to SVC(kernel='linear') while using the liblinear implementation.
  • Training accepts both dense feature matrices and sparse representations.
  • For multiple classes, it fits one binary model per class against all remaining classes.
  • L1 regularization can produce sparse feature-weight vectors, which may help with feature selection.
  • With dual set to auto, the solver selects the primal or dual formulation based on the problem dimensions and related settings.
  • C is the main regularization trade-off parameter and defaults to 1.0.

Common mistakes

  • Not every penalty and loss combination is valid; in particular, L1 regularization cannot be paired with hinge loss.

Example: Fit and predict with LinearSVC

from sklearn.svm import LinearSVC

X = [[0, 0], [1, 1], [1, 0], [0, 1]]
y = [0, 0, 1, 1]

model = LinearSVC(random_state=0, max_iter=10_000)
model.fit(X, y)
print(model.predict([[0.9, 0.1]]))

Creates a linear classifier, fits it to labeled samples, and predicts a class for a new sample.

When to use it

Large sparse classification

Classify text or other high-dimensional sparse feature vectors.

Sparse feature selection

Obtain a compact model with fewer active feature weights.

Multiclass prediction

Train a linear classifier across several target categories.

Interview questions

QWhat is LinearSVC and when would you choose it over SVC with a linear kernel?

LinearSVC is a linear support-vector classifier implemented with liblinear. Compared with SVC using a linear kernel, it offers different penalty and loss choices and is intended to scale better to many samples.

Follow-up: How are multiclass problems handled? The estimator trains one classifier per class in a one-vs-the-rest scheme.

QHow does C affect LinearSVC?

C controls the regularization strength inversely: smaller values apply stronger regularization, while larger values allow the model to fit the training data more closely. The default is 1.0.

Follow-up: What does class_weight do? It changes the weight of classes in the objective; balanced weighting derives weights from class frequencies.

QWhich learned attributes and prediction methods are useful after fitting?

The estimator exposes coef_ for the learned feature weights and intercept_ for the intercept. decision_function returns confidence scores, while predict maps samples to class labels.

Follow-up: What is a useful sparse-model configuration? Select penalty='l1' with a compatible loss to obtain sparse coefficient vectors.

  • sklearn.svm.SVC
  • sklearn.linear_model.LogisticRegression
  • sklearn.svm.NuSVC

Source: LinearSVC — scikit-learn 1.8.dev0 documentation. Checked 2026-10-15.