pub struct SparseSVM {
pub c: f64,
pub loss: String,
pub tol: f64,
pub max_iter: usize,
pub fit_intercept: bool,
pub positive: bool,
pub selection: String,
pub verbose: bool,
pub random_state: Option<u64>,
}Expand description
Sparse Support Vector Machine with L1 regularization
This implementation uses coordinate descent optimization with L1 penalty to automatically select relevant features and produce sparse solutions. The resulting model will have many zero coefficients, effectively performing feature selection during training.
§Parameters
C- Regularization parameter (default: 1.0)loss- Loss function type (‘hinge’ or ‘squared_hinge’, default: ‘squared_hinge’)tol- Tolerance for stopping criterion (default: 1e-4)max_iter- Maximum number of iterations (default: 1000)fit_intercept- Whether to fit an intercept term (default: true)positive- Force coefficients to be positive (default: false)selection- Selection strategy (‘cyclic’ or ‘random’, default: ‘cyclic’)random_state- Random seed for reproducible results (default: None)
§Example
use sklears_svm::SparseSVM;
use sklears_core::traits::{Predict, Fit};
use scirs2_core::ndarray::array;
let X = array![[1.0, 2.0, 0.0], [2.0, 3.0, 1.0], [3.0, 3.0, 0.0], [2.0, 1.0, 1.0]];
let y = array![0, 1, 1, 0];
let model = SparseSVM::new()
.with_c(1.0)
.with_max_iter(1000);
let trained_model = model.fit(&X, &y).expect("SparseSVM fit should succeed on valid input");
let predictions = trained_model.predict(&X).expect("SparseSVM predict should succeed on valid input");Fields§
§c: f64Regularization parameter
loss: StringLoss function (‘hinge’ or ‘squared_hinge’)
tol: f64Tolerance for stopping criterion
max_iter: usizeMaximum number of iterations
fit_intercept: boolWhether to fit an intercept term
positive: boolForce coefficients to be positive
selection: StringSelection strategy (‘cyclic’ or ‘random’)
verbose: boolVerbose output
random_state: Option<u64>Random seed
Implementations§
Source§impl SparseSVM
impl SparseSVM
Sourcepub fn with_max_iter(self, max_iter: usize) -> Self
pub fn with_max_iter(self, max_iter: usize) -> Self
Set the maximum number of iterations
Sourcepub fn with_fit_intercept(self, fit_intercept: bool) -> Self
pub fn with_fit_intercept(self, fit_intercept: bool) -> Self
Set whether to fit an intercept
Sourcepub fn with_positive(self, positive: bool) -> Self
pub fn with_positive(self, positive: bool) -> Self
Set whether to force positive coefficients
Sourcepub fn with_selection(self, selection: &str) -> Self
pub fn with_selection(self, selection: &str) -> Self
Set the selection strategy
Sourcepub fn with_verbose(self, verbose: bool) -> Self
pub fn with_verbose(self, verbose: bool) -> Self
Set verbose output
Sourcepub fn with_random_state(self, random_state: u64) -> Self
pub fn with_random_state(self, random_state: u64) -> Self
Set random state for reproducible results
Trait Implementations§
Source§impl Estimator for SparseSVM
impl Estimator for SparseSVM
Source§type Error = SklearsError
type Error = SklearsError
Source§fn validate_config(&self) -> Result<(), SklearsError>
fn validate_config(&self) -> Result<(), SklearsError>
Source§fn check_compatibility(
&self,
n_samples: usize,
n_features: usize,
) -> Result<(), SklearsError>
fn check_compatibility( &self, n_samples: usize, n_features: usize, ) -> Result<(), SklearsError>
Source§fn metadata(&self) -> EstimatorMetadata
fn metadata(&self) -> EstimatorMetadata
Source§impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 1]>>> for SparseSVM
impl Fit<ArrayBase<OwnedRepr<f64>, Dim<[usize; 2]>>, ArrayBase<OwnedRepr<i32>, Dim<[usize; 1]>>> for SparseSVM
Source§type Fitted = TrainedSparseSVM
type Fitted = TrainedSparseSVM
Source§fn fit(self, x: &Array2<f64>, y: &Array1<i32>) -> Result<TrainedSparseSVM>
fn fit(self, x: &Array2<f64>, y: &Array1<i32>) -> Result<TrainedSparseSVM>
Source§fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
fn fit_with_validation(
self,
x: &X,
y: &Y,
_x_val: Option<&X>,
_y_val: Option<&Y>,
) -> Result<(Self::Fitted, FitMetrics), SklearsError>where
Self: Sized,
Auto Trait Implementations§
impl Freeze for SparseSVM
impl RefUnwindSafe for SparseSVM
impl Send for SparseSVM
impl Sync for SparseSVM
impl Unpin for SparseSVM
impl UnsafeUnpin for SparseSVM
impl UnwindSafe for SparseSVM
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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