Skip to main content

SVC

Struct SVC 

Source
pub struct SVC<F, K> {
    pub kernel: K,
    pub c: F,
    pub tol: F,
    pub max_iter: usize,
    pub cache_size: usize,
    pub shrinking: bool,
    pub decision_function_shape: SvmDecisionShape,
    pub break_ties: bool,
    pub class_weight: ClassWeight<F>,
    pub probability: bool,
}
Expand description

Support Vector Classifier.

Uses Sequential Minimal Optimization (SMO) to solve the dual QP. Supports multiclass via one-vs-one strategy.

§Type Parameters

Fields§

§kernel: K

The kernel function.

§c: F

Regularization parameter (penalty for misclassification).

§tol: F

Convergence tolerance.

§max_iter: usize

Maximum number of SMO iterations. 0 is the sklearn max_iter=-1 sentinel meaning no iteration limit (the SMO runs to convergence); a non-zero value caps the iteration count (sklearn/svm/_classes.py, max_iter default -1).

§cache_size: usize

Size of the kernel evaluation LRU cache (perf-only; default 200 to match sklearn’s cache_size=200).

§shrinking: bool

Whether to use libsvm’s shrinking heuristic (sklearn/svm/_base.py:339, _classes.py shrinking=True).

ferrolearn’s SMO has no shrinking heuristic: shrinking is a libsvm performance optimization that does NOT change the converged optimum (R-DEV-7). This flag is accepted for API parity (default true, matching sklearn) but DOES NOT alter the fitted result — the converged α/dual_coef_/intercept_ are shrinking-invariant.

§decision_function_shape: SvmDecisionShape

The multiclass decision_function shape convention (sklearn/svm/_base.py:778-781); default SvmDecisionShape::Ovr (sklearn’s decision_function_shape='ovr').

§break_ties: bool

Whether predict breaks ties by the one-vs-rest decision confidence instead of the libsvm vote (break_ties, sklearn/svm/_classes.py default False; semantics in BaseSVC.predict, sklearn/svm/_base.py:801-814).

When true AND SvmDecisionShape::Ovr AND n_classes > 2, predict = argmax(decision_function(X)) (the ovr decision, which breaks ties by confidence); otherwise the libsvm ovo vote (with lower-index tie-break) is used. break_ties=true with SvmDecisionShape::Ovo is rejected at predict time (InvalidParameter), matching sklearn (_base.py:801-804).

§class_weight: ClassWeight<F>

Per-class scaling of C (class_weight, sklearn/svm/_classes.py:118-124). Default ClassWeight::None (all classes weighted 1.0). For an ovo pair (a, b) with a < b, the C of the y=+1 group (class b) is C·class_weight_[b] and the C of the y=-1 group (class a) is C·class_weight_[a]; the weights are computed ONCE over the full y by [compute_class_weight] (_base.py:740).

§probability: bool

Whether to enable Platt-scaling probability estimates (probability, sklearn/svm/_classes.py, default False).

When true, Fit::fit runs an internal 5-fold cross-validation per one-vs-one pair, fits a sigmoid 1/(1+exp(A·f+B)) over the out-of-fold decision values ([sigmoid_train], libsvm svm_binary_svc_probability, svm.cpp:2107-2203), and stores the per-pair (A, B) so FittedSVC::predict_proba/FittedSVC::predict_log_proba are available. When false (the default) predict_proba returns an error (_base.py:820-827).

RNG boundary (documented divergence). libsvm’s svm_binary_svc_probability shuffles the CV fold assignment with an RNG seeded by random_state, so sklearn’s probA_/probB_ (and hence the exact predict_proba values) are NON-DETERMINISTIC across random_state — the docstring itself warns “the results can be slightly different than those obtained by predict”. ferrolearn instead uses a DETERMINISTIC 5-fold split (contiguous folds, no RNG shuffle), so it CANNOT and DOES NOT bit-match sklearn’s predict_proba values. What is reproduced exactly is the DETERMINISTIC machinery ([sigmoid_train], [sigmoid_predict], [multiclass_probability]) and the STRUCTURAL contract (rows sum to 1, entries in [0, 1], monotone in the binary decision value, the raise-when-probability=false). This is analogous to the SGD shuffle boundary already documented in this codebase.

Implementations§

Source§

impl<F: Float, K: Kernel<F>> SVC<F, K>

Source

pub fn new(kernel: K) -> Self

Create a new SVC with the given kernel and default hyperparameters matching sklearn (sklearn/svm/_classes.py SVC.__init__).

Defaults: C = 1.0, tol = 1e-3, max_iter = 0 (= sklearn -1, no iteration limit), cache_size = 200, shrinking = true, decision_function_shape = Ovr, break_ties = false, class_weight = None, probability = false.

Source

pub fn with_probability(self, probability: bool) -> Self

Enable/disable Platt-scaling probability estimates (sklearn probability, default false). When true, Fit::fit runs the internal per-pair 5-fold CV + [sigmoid_train] so FittedSVC::predict_proba/FittedSVC::predict_log_proba are available; when false they return an error.

See the SVC::probability field doc for the documented RNG-CV exact-value boundary (sklearn is non-deterministic across random_state; only the deterministic machinery + structural invariants + the raise contract are reproduced).

Source

pub fn with_class_weight(self, class_weight: ClassWeight<F>) -> Self

Set the per-class C scaling (sklearn class_weight, _classes.py:118-124). ClassWeight::None (default) leaves every class at 1.0; ClassWeight::Balanced uses n_samples / (n_classes · count_c); ClassWeight::Explicit takes a (label, weight) map (unlisted classes default to 1.0).

Source

pub fn with_shrinking(self, shrinking: bool) -> Self

Set the shrinking flag (sklearn shrinking, default true).

Accepted for API parity; does NOT alter the converged optimum (ferrolearn’s SMO has no shrinking heuristic — R-DEV-7).

Source

pub fn with_break_ties(self, break_ties: bool) -> Self

Set the break_ties flag (sklearn break_ties, default false, sklearn/svm/_base.py:801-814).

Source

pub fn with_decision_function_shape(self, shape: SvmDecisionShape) -> Self

Set the multiclass decision_function shape convention ('ovr' default / 'ovo', sklearn/svm/_base.py:778-781).

Source

pub fn with_c(self, c: F) -> Self

Set the regularization parameter C.

Source

pub fn with_tol(self, tol: F) -> Self

Set the convergence tolerance.

Source

pub fn with_max_iter(self, max_iter: usize) -> Self

Set the maximum number of SMO iterations.

Source

pub fn with_cache_size(self, cache_size: usize) -> Self

Set the kernel cache size.

Trait Implementations§

Source§

impl<F: Clone, K: Clone> Clone for SVC<F, K>

Source§

fn clone(&self) -> SVC<F, K>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<F: Debug, K: Debug> Debug for SVC<F, K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F: Float + Send + Sync + ScalarOperand + 'static, K: Kernel<F> + 'static> Fit<ArrayBase<OwnedRepr<F>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<usize>, Dim<[usize; 1]>>> for SVC<F, K>

Source§

fn fit( &self, x: &Array2<F>, y: &Array1<usize>, ) -> Result<FittedSVC<F, K>, FerroError>

Fit the SVC model using SMO.

§Errors

Returns FerroError::ShapeMismatch if x and y have different sample counts. Returns FerroError::InvalidParameter if C is not positive. Returns FerroError::InsufficientSamples if fewer than 2 classes.

Source§

type Fitted = FittedSVC<F, K>

The fitted model type returned by fit.
Source§

type Error = FerroError

The error type returned by fit.

Auto Trait Implementations§

§

impl<F, K> Freeze for SVC<F, K>
where K: Freeze, F: Freeze,

§

impl<F, K> RefUnwindSafe for SVC<F, K>

§

impl<F, K> Send for SVC<F, K>
where K: Send, F: Send,

§

impl<F, K> Sync for SVC<F, K>
where K: Sync, F: Sync,

§

impl<F, K> Unpin for SVC<F, K>
where K: Unpin, F: Unpin,

§

impl<F, K> UnsafeUnpin for SVC<F, K>
where K: UnsafeUnpin, F: UnsafeUnpin,

§

impl<F, K> UnwindSafe for SVC<F, K>
where K: UnwindSafe, F: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V