SVC
Module: strata.svm • Kind: struct • Traits: Classifier, Copyable, Movable, Serializable
Source: strata/svm/svc.mojo
struct SVC[compute_dtype: DType = DType.float64](Classifier, Copyable, Movable, Serializable)from strata.svm import SVCC-Support Vector Classification using non-linear kernels and SMO.
Fits maximum-margin non-linear decision boundaries using Sequential Minimal Optimization (SMO) across arbitrary kernel mappings (RBF, Polynomial, Sigmoid, and Linear), with One-vs-Rest (OvR) multiclass scaling.
Parameters (Compile-Time)
Section titled “Parameters (Compile-Time)”| Parameter | Description |
|---|---|
compute_dtype |
Floating point precision for kernel operations. Default DType.float64. |
Constructors
Section titled “Constructors”def __init__( out self, C: Float64 = 1.0, kernel: String = "rbf", degree: Int = 3, gamma: String = "scale", gamma_val: Float64 = -1.0, coef0: Float64 = 0.0, tol: Float64 = 1e-3, max_iter: Int = 10000, decision_function_shape: String = "ovr",)| Argument | Type | Description |
|---|---|---|
C |
Float64 |
Regularization parameter. Strength is inversely proportional to C. Must be strictly positive. Default 1.0. |
kernel |
String |
Kernel routine (‘rbf’, ‘linear’, ‘poly’, ‘sigmoid’). Default ‘rbf’. |
degree |
Int |
Degree for polynomial kernel function. Ignored by others. Default 3. |
gamma |
String |
Kernel scaling mode (‘scale’ or ‘auto’). Default ‘scale’. |
gamma_val |
Float64 |
Explicit numeric gamma. When > 0, overrides gamma mode. Default -1.0. |
coef0 |
Float64 |
Independent term in poly and sigmoid kernels. Default 0.0. |
tol |
Float64 |
Tolerance for stopping criterion. Default 1e-3. |
max_iter |
Int |
Hard limit on SMO solver iterations. Default 10000. |
decision_function_shape |
String |
Multiclass strategy (‘ovr’). Default ‘ovr’. |
Attributes
Section titled “Attributes”| Attribute | Description |
|---|---|
classes_ |
Unique sorted class labels seen during fit. |
support_vectors_ |
Extracted support vectors of shape (n_support_vectors, n_features). |
support_indices_ |
Row indices of support vectors in original training set. |
dual_coef_ |
Dual coefficients alpha_i * y_i for support vectors. Shape (1, n_support_vectors) for binary, (n_classes, n_support_vectors) for multiclass. |
intercept_ |
Bias terms b of length 1 for binary, length n_classes for multiclass. |
n_features_in_ |
Number of features seen during fit. |
n_iter_ |
Maximum iterations reached across binary solver subproblems. |
gamma_ |
Evaluated kernel scale coefficient. |
is_fitted |
Boolean flag indicating if estimator has been fitted. |
Methods Overview
Section titled “Methods Overview”| Method | Description |
|---|---|
SVC.fit() |
Fits the kernel Support Vector Classifier on feature matrix X and labels y. |
SVC.decision_function() |
Predict confidence scores for samples in X. |
SVC.predict() |
Predict class labels for samples in X. |
SVC.predict_proba() |
Probability estimates using calibrated decision scores. |
SVC.serialize() |
Serializes SVC parameters and fitted state into BufferWriter. |
SVC.deserialize() |
Deserializes SVC from BufferReader. |
Method Details
Section titled “Method Details”SVC.fit()
Section titled “SVC.fit()”def fit[feat_dtype: DType, target_dtype: DType]( mut self, X: Matrix[feat_dtype], y: List[Scalar[target_dtype]],)
def fit[feat_dtype: DType, target_dtype: DType]( mut self, dataset: Dataset[feat_dtype, target_dtype],)Overload Note: This method accepts either standard
(X, y)inputs or a unifieddataset: Datasetcontainer.
Fits the kernel Support Vector Classifier on feature matrix X and labels y.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[feat_dtype] |
Training feature matrix of shape (n_samples, n_features). |
y |
List[Scalar[target_dtype]] |
Target class labels of length n_samples. |
dataset |
Dataset[feat_dtype, target_dtype] |
Dataset container holding feature matrix and targets. (Can be provided alternatively in place of (X, y)) |
SVC.decision_function()
Section titled “SVC.decision_function()”def decision_function[feat_dtype: DType]( self, X: Matrix[feat_dtype],) -> Matrix[Self.compute_dtype]Predict confidence scores for samples in X.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[feat_dtype] |
Input feature matrix of shape (n_samples, n_features). |
Returns: Matrix[Self.compute_dtype] — Matrix[compute_dtype]: Shape (n_samples, 1) for binary, or (n_samples, n_classes) for multiclass.
SVC.predict()
Section titled “SVC.predict()”def predict[feat_dtype: DType](self, X: Matrix[feat_dtype]) -> List[Int]
def predict[feat_dtype: DType, target_dtype: DType]( self, dataset: Dataset[feat_dtype, target_dtype],) -> List[Int]Overload Note: This method accepts either standard
(X, y)inputs or a unifieddataset: Datasetcontainer.
Predict class labels for samples in X.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[feat_dtype] |
Input feature matrix of shape (n_samples, n_features). |
dataset |
Dataset[feat_dtype, target_dtype] |
Dataset container holding feature matrix and targets. (Can be provided alternatively in place of (X, y)) |
Returns: List[Int] — List[Int]: Predicted discrete class labels for each sample.
SVC.predict_proba()
Section titled “SVC.predict_proba()”def predict_proba[feat_dtype: DType]( self, X: Matrix[feat_dtype],) -> Matrix[feat_dtype]
def predict_proba[feat_dtype: DType, target_dtype: DType]( self, dataset: Dataset[feat_dtype, target_dtype],) -> Matrix[ feat_dtype ]Overload Note: This method accepts either standard
(X, y)inputs or a unifieddataset: Datasetcontainer.
Probability estimates using calibrated decision scores.
| Parameter | Type | Description |
|---|---|---|
X |
Matrix[feat_dtype] |
Input feature matrix of shape (n_samples, n_features). |
dataset |
Dataset[feat_dtype, target_dtype] |
Dataset container holding feature matrix and targets. (Can be provided alternatively in place of (X, y)) |
Returns: Matrix[feat_dtype] — Matrix[feat_dtype]: Probability matrix of shape (n_samples, n_classes).
SVC.serialize()
Section titled “SVC.serialize()”def serialize(self, mut writer: BufferWriter)Serializes SVC parameters and fitted state into BufferWriter.
SVC.deserialize()
Section titled “SVC.deserialize()”def deserialize(mut reader: BufferReader) -> SelfDeserializes SVC from BufferReader.
Returns: Self
Section titled “Returns: Self”Example
Section titled “Example”from strata.svm import SVCfrom strata.core import Matrix
var clf = SVC[DType.float64](C=1.0, kernel="rbf")clf.fit(X_train, y_train)var preds = clf.predict(X_test)