skglm.LinearSVC#
- class skglm.LinearSVC(C=1.0, max_iter=50, max_epochs=50000, p0=10, verbose=0, tol=0.0001, fit_intercept=True, warm_start=False, ws_strategy='subdiff')[source]#
LinearSVC estimator, with hinge loss.
The optimization objective for LinearSVC is:
`C xx sum_(i=1)^(n_"samples") max(0, 1 - y_i beta^T X[i, :]) + 1/2 ||beta||_2 ^ 2`i.e. hinge datafit loss (non-smooth) + l2 regularization (smooth)
To solve this, we solve the dual optimization problem to stay in our framework of smooth datafit and non-smooth penalty. The dual optimization problem of SVC is:
`1/2 ||(yX)^T w||_2 ^ 2 - \sum_(i=1)^(n_"samples") w_i + \sum_(i=1)^(n_"samples") [0 <= w_i <= C]`The primal-dual relation is given by:
`w = \sum_(i=1)^(n_"samples") y_i w_i X[i, :]`- Parameters:
- Cfloat, optional
Regularization parameter. The strength of the regularization is inversely proportional to C. Must be strictly positive.
- max_iterint, optional
The maximum number of iterations (subproblem definitions).
- max_epochsint
Maximum number of CD epochs on each subproblem.
- p0int
First working set size.
- verbosebool or int
Amount of verbosity.
- tolfloat, optional
Stopping criterion for the optimization.
- fit_interceptbool, optional (default=True)
Whether or not to fit an intercept.
- warm_startbool, optional (default=False)
When set to
True
, reuse the solution of the previous call to fit as initialization, otherwise, just erase the previous solution.- ws_strategystr
The score used to build the working set. Can be
fixpoint
orsubdiff
.
- Attributes:
- coef_array, shape (n_features,)
parameter vector (`w` in the cost function formula)
- sparse_coef_scipy.sparse matrix, shape (n_features, 1)
sparse_coef_
is a readonly property derived fromcoef_
- intercept_float
constant term in decision function.
- dual_array, shape (n_samples,)
dual of the solution.
- n_iter_int
Number of subproblems solved to reach the specified tolerance.
- __init__(C=1.0, max_iter=50, max_epochs=50000, p0=10, verbose=0, tol=0.0001, fit_intercept=True, warm_start=False, ws_strategy='subdiff')[source]#
Methods
__init__
([C, max_iter, max_epochs, p0, ...])decision_function
(X)Predict confidence scores for samples.
densify
()Convert coefficient matrix to dense array format.
fit
(X, y)Fit LinearSVC classifier.
get_metadata_routing
()Get metadata routing of this object.
get_params
([deep])Get parameters for this estimator.
predict
(X)Predict class labels for samples in X.
score
(X, y[, sample_weight])Return the mean accuracy on the given test data and labels.
set_params
(**params)Set the parameters of this estimator.
set_score_request
(*[, sample_weight])Request metadata passed to the
score
method.sparsify
()Convert coefficient matrix to sparse format.