pub struct GraphSemiSupervisedSVM {
pub c: f64,
pub gamma_a: f64,
pub gamma_i: f64,
pub kernel: String,
pub graph_kernel: String,
pub n_neighbors: usize,
pub sigma: f64,
pub max_iter: usize,
pub tol: f64,
pub verbose: bool,
}Expand description
Graph-based Semi-supervised Support Vector Machine
This implementation combines SVM with graph-based label propagation, using the graph structure to regularize the learning process and propagate information from labeled to unlabeled examples.
§Parameters
C- Regularization parameter for SVM (default: 1.0)gamma_a- Graph regularization parameter (default: 0.1)gamma_i- Intrinsic regularization parameter (default: 0.01)kernel- Kernel function for SVM (‘rbf’, ‘linear’, default: ‘rbf’)graph_kernel- Kernel for graph construction (‘rbf’, ‘knn’, default: ‘rbf’)n_neighbors- Number of neighbors for k-NN graph (default: 10)sigma- Bandwidth for RBF kernel (default: 1.0)max_iter- Maximum number of iterations (default: 1000)tol- Tolerance for convergence (default: 1e-4)verbose- Enable verbose output (default: false)
§Example
use sklears_svm::GraphSemiSupervisedSVM;
use sklears_core::traits::{Predict};
use scirs2_core::ndarray::array;
let X_labeled = array![[1.0, 2.0], [2.0, 3.0]];
let y_labeled = array![0, 1];
let X_unlabeled = array![[1.5, 2.5], [2.5, 3.5]];
let model = GraphSemiSupervisedSVM::new()
.with_c(1.0)
.with_gamma_a(0.1);
let trained_model = model
.fit_semi_supervised(&X_labeled, &y_labeled, &X_unlabeled)
.expect("GraphSemiSupervisedSVM fit_semi_supervised should succeed on valid input");
let predictions = trained_model.predict(&X_labeled).expect("GraphSemiSupervisedSVM predict should succeed on valid input");Fields§
§c: f64SVM regularization parameter
gamma_a: f64Graph regularization parameter
gamma_i: f64Intrinsic regularization parameter
kernel: StringKernel function for SVM
graph_kernel: StringKernel function for graph construction
n_neighbors: usizeNumber of neighbors for k-NN graph
sigma: f64Bandwidth for RBF kernel
max_iter: usizeMaximum number of iterations
tol: f64Tolerance for convergence
verbose: boolVerbose output
Implementations§
Source§impl GraphSemiSupervisedSVM
impl GraphSemiSupervisedSVM
Sourcepub fn with_gamma_a(self, gamma_a: f64) -> Self
pub fn with_gamma_a(self, gamma_a: f64) -> Self
Set the graph regularization parameter
Sourcepub fn with_gamma_i(self, gamma_i: f64) -> Self
pub fn with_gamma_i(self, gamma_i: f64) -> Self
Set the intrinsic regularization parameter
Sourcepub fn with_kernel(self, kernel: &str) -> Self
pub fn with_kernel(self, kernel: &str) -> Self
Set the SVM kernel function
Sourcepub fn with_graph_kernel(self, graph_kernel: &str) -> Self
pub fn with_graph_kernel(self, graph_kernel: &str) -> Self
Set the graph construction kernel
Sourcepub fn with_n_neighbors(self, n_neighbors: usize) -> Self
pub fn with_n_neighbors(self, n_neighbors: usize) -> Self
Set the number of neighbors for k-NN graph
Sourcepub fn with_sigma(self, sigma: f64) -> Self
pub fn with_sigma(self, sigma: f64) -> Self
Set the RBF kernel bandwidth
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_verbose(self, verbose: bool) -> Self
pub fn with_verbose(self, verbose: bool) -> Self
Set verbose output
Sourcepub fn fit_semi_supervised(
self,
x_labeled: &Array2<f64>,
y_labeled: &Array1<i32>,
x_unlabeled: &Array2<f64>,
) -> Result<TrainedGraphSemiSupervisedSVM>
pub fn fit_semi_supervised( self, x_labeled: &Array2<f64>, y_labeled: &Array1<i32>, x_unlabeled: &Array2<f64>, ) -> Result<TrainedGraphSemiSupervisedSVM>
Train graph-based semi-supervised SVM
Trait Implementations§
Source§impl Clone for GraphSemiSupervisedSVM
impl Clone for GraphSemiSupervisedSVM
Source§fn clone(&self) -> GraphSemiSupervisedSVM
fn clone(&self) -> GraphSemiSupervisedSVM
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GraphSemiSupervisedSVM
impl Debug for GraphSemiSupervisedSVM
Source§impl Default for GraphSemiSupervisedSVM
impl Default for GraphSemiSupervisedSVM
Source§impl Estimator for GraphSemiSupervisedSVM
impl Estimator for GraphSemiSupervisedSVM
Source§type Config = GraphSemiSupervisedSVM
type Config = GraphSemiSupervisedSVM
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
Auto Trait Implementations§
impl Freeze for GraphSemiSupervisedSVM
impl RefUnwindSafe for GraphSemiSupervisedSVM
impl Send for GraphSemiSupervisedSVM
impl Sync for GraphSemiSupervisedSVM
impl Unpin for GraphSemiSupervisedSVM
impl UnsafeUnpin for GraphSemiSupervisedSVM
impl UnwindSafe for GraphSemiSupervisedSVM
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