Class: 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.
To learn how to tune SVC’s hyperparameters, see the following example: Nested versus non-nested cross-validation
Read more in the User Guide.
Constructors
new SVC()
new SVC(
opts
?):SVC
Parameters
Parameter | Type | Description |
---|---|---|
opts ? | object | - |
opts.break_ties ? | boolean | If 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. |
opts.C ? | number | Regularization parameter. The strength of the regularization is inversely proportional to C. Must be strictly positive. The penalty is a squared l2 penalty. For an intuitive visualization of the effects of scaling the regularization parameter C, see Scaling the regularization parameter for SVCs. |
opts.cache_size ? | number | Specify the size of the kernel cache (in MB). |
opts.class_weight ? | any | Set 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 ? | number | Independent term in kernel function. It is only significant in ‘poly’ and ‘sigmoid’. |
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. |
opts.degree ? | number | Degree of the polynomial kernel function (‘poly’). Must be non-negative. Ignored by all other kernels. |
opts.gamma ? | number | "auto" | "scale" | Kernel coefficient for ‘rbf’, ‘poly’ and ‘sigmoid’. |
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) . For an intuitive visualization of different kernel types see Plot classification boundaries with different SVM Kernels. |
opts.max_iter ? | number | Hard limit on iterations within solver, or -1 for no limit. |
opts.probability ? | boolean | Whether 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. |
opts.random_state ? | number | Controls 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 ? | boolean | Whether to use the shrinking heuristic. See the User Guide. |
opts.tol ? | number | Tolerance for stopping criterion. |
opts.verbose ? | boolean | Enable 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. |
Returns SVC
Defined in generated/svm/SVC.ts:31
Properties
Property | Type | Default value | Defined in |
---|---|---|---|
_isDisposed | boolean | false | generated/svm/SVC.ts:29 |
_isInitialized | boolean | false | generated/svm/SVC.ts:28 |
_py | PythonBridge | undefined | generated/svm/SVC.ts:27 |
id | string | undefined | generated/svm/SVC.ts:24 |
opts | any | undefined | generated/svm/SVC.ts:25 |
Accessors
class_weight_
Get Signature
get class_weight_():
Promise
<ArrayLike
>
Multipliers of parameter C for each class. Computed based on the class_weight
parameter.
Returns Promise
<ArrayLike
>
Defined in generated/svm/SVC.ts:530
classes_
Get Signature
get classes_():
Promise
<ArrayLike
>
The classes labels.
Returns Promise
<ArrayLike
>
Defined in generated/svm/SVC.ts:553
dual_coef_
Get Signature
get dual_coef_():
Promise
<ArrayLike
[]>
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.
Returns Promise
<ArrayLike
[]>
Defined in generated/svm/SVC.ts:575
feature_names_in_
Get Signature
get feature_names_in_():
Promise
<ArrayLike
>
Names of features seen during fit. Defined only when X
has feature names that are all strings.
Returns Promise
<ArrayLike
>
Defined in generated/svm/SVC.ts:665
fit_status_
Get Signature
get fit_status_():
Promise
<number
>
0 if correctly fitted, 1 otherwise (will raise warning)
Returns Promise
<number
>
Defined in generated/svm/SVC.ts:597
intercept_
Get Signature
get intercept_():
Promise
<ArrayLike
>
Constants in decision function.
Returns Promise
<ArrayLike
>
Defined in generated/svm/SVC.ts:620
n_features_in_
Get Signature
get n_features_in_():
Promise
<number
>
Number of features seen during fit.
Returns Promise
<number
>
Defined in generated/svm/SVC.ts:642
n_iter_
Get Signature
get n_iter_():
Promise
<ArrayLike
>
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.
Returns Promise
<ArrayLike
>
Defined in generated/svm/SVC.ts:688
py
Get Signature
get py():
PythonBridge
Returns PythonBridge
Set Signature
set py(
pythonBridge
):void
Parameters
Parameter | Type |
---|---|
pythonBridge | PythonBridge |
Returns void
Defined in generated/svm/SVC.ts:137
shape_fit_
Get Signature
get shape_fit_():
Promise
<any
[]>
Array dimensions of training vector X
.
Returns Promise
<any
[]>
Defined in generated/svm/SVC.ts:755
support_
Get Signature
get support_():
Promise
<ArrayLike
>
Indices of support vectors.
Returns Promise
<ArrayLike
>
Defined in generated/svm/SVC.ts:710
support_vectors_
Get Signature
get support_vectors_():
Promise
<ArrayLike
[]>
Support vectors. An empty array if kernel is precomputed.
Returns Promise
<ArrayLike
[]>
Defined in generated/svm/SVC.ts:732
Methods
decision_function()
decision_function(
opts
):Promise
<ArrayLike
[]>
Evaluate the decision function for the samples in X.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.X ? | ArrayLike [] | The input samples. |
Returns Promise
<ArrayLike
[]>
Defined in generated/svm/SVC.ts:205
dispose()
dispose():
Promise
<void
>
Disposes of the underlying Python resources.
Once dispose()
is called, the instance is no longer usable.
Returns Promise
<void
>
Defined in generated/svm/SVC.ts:188
fit()
fit(
opts
):Promise
<any
>
Fit the SVM model according to the given training data.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Per-sample weights. Rescale C per sample. Higher weights force the classifier to put more emphasis on these points. |
opts.X ? | ArrayLike | Training 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.y ? | ArrayLike | Target values (class labels in classification, real numbers in regression). |
Returns Promise
<any
>
Defined in generated/svm/SVC.ts:237
get_metadata_routing()
get_metadata_routing(
opts
):Promise
<any
>
Get metadata routing of this object.
Please check User Guide on how the routing mechanism works.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.routing ? | any | A MetadataRequest encapsulating routing information. |
Returns Promise
<any
>
Defined in generated/svm/SVC.ts:280
init()
init(
py
):Promise
<void
>
Initializes the underlying Python resources.
This instance is not usable until the Promise
returned by init()
resolves.
Parameters
Parameter | Type |
---|---|
py | PythonBridge |
Returns Promise
<void
>
Defined in generated/svm/SVC.ts:150
predict()
predict(
opts
):Promise
<ArrayLike
>
Perform classification on samples in X.
For an one-class model, +1 or -1 is returned.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
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:314
predict_log_proba()
predict_log_proba(
opts
):Promise
<ArrayLike
[]>
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
.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
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:348
predict_proba()
predict_proba(
opts
):Promise
<ArrayLike
[]>
Compute probabilities of possible outcomes for samples in X.
The model needs to have probability information computed at training time: fit with attribute probability
set to true
.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
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:382
score()
score(
opts
):Promise
<number
>
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.
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | ArrayLike | Sample weights. |
opts.X ? | ArrayLike [] | Test samples. |
opts.y ? | ArrayLike | True labels for X . |
Returns Promise
<number
>
Defined in generated/svm/SVC.ts:416
set_fit_request()
set_fit_request(
opts
):Promise
<any
>
Request metadata passed to the fit
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in fit . |
Returns Promise
<any
>
Defined in generated/svm/SVC.ts:462
set_score_request()
set_score_request(
opts
):Promise
<any
>
Request metadata passed to the score
method.
Note that this method is only relevant if enable_metadata_routing=True
(see sklearn.set_config
). Please see User Guide on how the routing mechanism works.
The options for each parameter are:
Parameters
Parameter | Type | Description |
---|---|---|
opts | object | - |
opts.sample_weight ? | string | boolean | Metadata routing for sample_weight parameter in score . |
Returns Promise
<any
>
Defined in generated/svm/SVC.ts:498