Documentation
Classes
SVC

SVC

C-Support Vector Classification.

The implementation is based on libsvm. The fit time scales at least quadratically with the number of samples and may be impractical beyond tens of thousands of samples. For large datasets consider using LinearSVC or SGDClassifier instead, possibly after a Nystroem transformer or other Kernel Approximation.

The multiclass support is handled according to a one-vs-one scheme.

For details on the precise mathematical formulation of the provided kernel functions and how gamma, coef0 and degree affect each other, see the corresponding section in the narrative documentation: Kernel functions.

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new SVC(opts?: object): SVC;

Parameters

NameTypeDescription
opts?object-
opts.C?numberRegularization parameter. The strength of the regularization is inversely proportional to C. Must be strictly positive. The penalty is a squared l2 penalty. Default Value 1
opts.break_ties?booleanIf true, decision\_function\_shape='ovr', and number of classes > 2, predict will break ties according to the confidence values of decision_function; otherwise the first class among the tied classes is returned. Please note that breaking ties comes at a relatively high computational cost compared to a simple predict. Default Value false
opts.cache_size?numberSpecify the size of the kernel cache (in MB). Default Value 200
opts.class_weight?anySet the parameter C of class i to class_weight[i]*C for SVC. If not given, all classes are supposed to have weight one. The “balanced” mode uses the values of y to automatically adjust weights inversely proportional to class frequencies in the input data as n\_samples / (n\_classes \* np.bincount(y)).
opts.coef0?numberIndependent term in kernel function. It is only significant in ‘poly’ and ‘sigmoid’. Default Value 0
opts.decision_function_shape?"ovr" | "ovo"Whether to return a one-vs-rest (‘ovr’) decision function of shape (n_samples, n_classes) as all other classifiers, or the original one-vs-one (‘ovo’) decision function of libsvm which has shape (n_samples, n_classes * (n_classes - 1) / 2). However, note that internally, one-vs-one (‘ovo’) is always used as a multi-class strategy to train models; an ovr matrix is only constructed from the ovo matrix. The parameter is ignored for binary classification. Default Value 'ovr'
opts.degree?numberDegree of the polynomial kernel function (‘poly’). Must be non-negative. Ignored by all other kernels. Default Value 3
opts.gamma?number | "auto" | "scale"Kernel coefficient for ‘rbf’, ‘poly’ and ‘sigmoid’. Default Value 'scale'
opts.kernel?"sigmoid" | "precomputed" | "linear" | "poly" | "rbf"Specifies the kernel type to be used in the algorithm. If none is given, ‘rbf’ will be used. If a callable is given it is used to pre-compute the kernel matrix from data matrices; that matrix should be an array of shape (n\_samples, n\_samples). Default Value 'rbf'
opts.max_iter?numberHard limit on iterations within solver, or -1 for no limit. Default Value -1
opts.probability?booleanWhether to enable probability estimates. This must be enabled prior to calling fit, will slow down that method as it internally uses 5-fold cross-validation, and predict\_proba may be inconsistent with predict. Read more in the User Guide. Default Value false
opts.random_state?numberControls the pseudo random number generation for shuffling the data for probability estimates. Ignored when probability is false. Pass an int for reproducible output across multiple function calls. See Glossary.
opts.shrinking?booleanWhether to use the shrinking heuristic. See the User Guide. Default Value true
opts.tol?numberTolerance for stopping criterion. Default Value 0.001
opts.verbose?booleanEnable verbose output. Note that this setting takes advantage of a per-process runtime setting in libsvm that, if enabled, may not work properly in a multithreaded context. Default Value false

Returns

SVC

Defined in: generated/svm/SVC.ts:29 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/svm/SVC.ts:27 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/svm/SVC.ts:26 (opens in a new tab)

_py

PythonBridge

Defined in: generated/svm/SVC.ts:25 (opens in a new tab)

id

string

Defined in: generated/svm/SVC.ts:22 (opens in a new tab)

opts

any

Defined in: generated/svm/SVC.ts:23 (opens in a new tab)

Accessors

class_weight_

Multipliers of parameter C for each class. Computed based on the class\_weight parameter.

Signature

class_weight_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/svm/SVC.ts:453 (opens in a new tab)

classes_

The classes labels.

Signature

classes_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/svm/SVC.ts:476 (opens in a new tab)

dual_coef_

Dual coefficients of the support vector in the decision function (see Mathematical formulation), multiplied by their targets. For multiclass, coefficient for all 1-vs-1 classifiers. The layout of the coefficients in the multiclass case is somewhat non-trivial. See the multi-class section of the User Guide for details.

Signature

dual_coef_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/svm/SVC.ts:498 (opens in a new tab)

feature_names_in_

Names of features seen during fit. Defined only when X has feature names that are all strings.

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/svm/SVC.ts:588 (opens in a new tab)

fit_status_

0 if correctly fitted, 1 otherwise (will raise warning)

Signature

fit_status_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/svm/SVC.ts:520 (opens in a new tab)

intercept_

Constants in decision function.

Signature

intercept_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/svm/SVC.ts:543 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/svm/SVC.ts:565 (opens in a new tab)

n_iter_

Number of iterations run by the optimization routine to fit the model. The shape of this attribute depends on the number of models optimized which in turn depends on the number of classes.

Signature

n_iter_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/svm/SVC.ts:611 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/svm/SVC.ts:135 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/svm/SVC.ts:139 (opens in a new tab)

shape_fit_

Array dimensions of training vector X.

Signature

shape_fit_(): Promise<any[]>;

Returns

Promise<any[]>

Defined in: generated/svm/SVC.ts:678 (opens in a new tab)

support_

Indices of support vectors.

Signature

support_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/svm/SVC.ts:633 (opens in a new tab)

support_vectors_

Support vectors.

Signature

support_vectors_(): Promise<ArrayLike[]>;

Returns

Promise<ArrayLike[]>

Defined in: generated/svm/SVC.ts:655 (opens in a new tab)

Methods

decision_function()

Evaluate the decision function for the samples in X.

Signature

decision_function(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]The input samples.

Returns

Promise<ArrayLike[]>

Defined in: generated/svm/SVC.ts:220 (opens in a new tab)

dispose()

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/svm/SVC.ts:203 (opens in a new tab)

fit()

Fit the SVM model according to the given training data.

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeTraining vectors, where n\_samples is the number of samples and n\_features is the number of features. For kernel=”precomputed”, the expected shape of X is (n_samples, n_samples).
opts.sample_weight?ArrayLikePer-sample weights. Rescale C per sample. Higher weights force the classifier to put more emphasis on these points.
opts.y?ArrayLikeTarget values (class labels in classification, real numbers in regression).

Returns

Promise<any>

Defined in: generated/svm/SVC.ts:253 (opens in a new tab)

init()

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/svm/SVC.ts:148 (opens in a new tab)

predict()

Perform classification on samples in X.

For an one-class model, +1 or -1 is returned.

Signature

predict(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeFor kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).

Returns

Promise<ArrayLike>

Defined in: generated/svm/SVC.ts:301 (opens in a new tab)

predict_log_proba()

Compute log probabilities of possible outcomes for samples in X.

The model need to have probability information computed at training time: fit with attribute probability set to true.

Signature

predict_log_proba(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).

Returns

Promise<ArrayLike[]>

Defined in: generated/svm/SVC.ts:336 (opens in a new tab)

predict_proba()

Compute probabilities of possible outcomes for samples in X.

The model need to have probability information computed at training time: fit with attribute probability set to true.

Signature

predict_proba(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]For kernel=”precomputed”, the expected shape of X is (n_samples_test, n_samples_train).

Returns

Promise<ArrayLike[]>

Defined in: generated/svm/SVC.ts:371 (opens in a new tab)

score()

Return the mean accuracy on the given test data and labels.

In multi-label classification, this is the subset accuracy which is a harsh metric since you require for each sample that each label set be correctly predicted.

Signature

score(opts: object): Promise<number>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Test samples.
opts.sample_weight?ArrayLikeSample weights.
opts.y?ArrayLikeTrue labels for X.

Returns

Promise<number>

Defined in: generated/svm/SVC.ts:406 (opens in a new tab)