pub trait AlgorithmPlugin<X, Y, Output>:
Plugin
+ Send
+ Sync {
type Fitted: Predict<X, Output> + Send + Sync;
// Required methods
fn fit(&self, x: &X, y: &Y) -> Result<Self::Fitted>;
fn predict(&self, fitted: &Self::Fitted, x: &X) -> Result<Output>;
fn get_parameters(&self) -> HashMap<String, PluginParameter>;
fn set_parameters(
&mut self,
params: HashMap<String, PluginParameter>,
) -> Result<()>;
}Expand description
Trait for algorithm plugins that can fit and predict
This trait defines the interface for machine learning algorithms that follow the fit/predict pattern. It extends the base Plugin trait with algorithm-specific functionality.
§Type Parameters
X- The input feature type (e.g.,Array2<f64>)Y- The target/label type (e.g.,Array1<f64>)Output- The prediction output type
§Examples
ⓘ
use sklears_core::plugin::{Plugin, AlgorithmPlugin, PluginParameter};
use sklears_core::traits::Predict;
use sklears_core::error::Result;
use std::collections::HashMap;
#[derive(Debug)]
struct LinearRegression {
// algorithm parameters
}
struct FittedLinearRegression {
// fitted model state
}
impl Predict<Vec<f64>, Vec<f64>> for FittedLinearRegression {
fn predict(&self, x: &Vec<f64>) -> Result<Vec<f64>> {
// prediction implementation
Ok(x.clone())
}
}
impl AlgorithmPlugin<Vec<f64>, Vec<f64>, Vec<f64>> for LinearRegression {
type Fitted = FittedLinearRegression;
fn fit(&self, x: &Vec<f64>, y: &Vec<f64>) -> Result<Self::Fitted> {
Ok(FittedLinearRegression {})
}
fn predict(&self, fitted: &Self::Fitted, x: &Vec<f64>) -> Result<Vec<f64>> {
fitted.predict(x)
}
fn get_parameters(&self) -> HashMap<String, PluginParameter> {
HashMap::new()
}
fn set_parameters(&mut self, _params: HashMap<String, PluginParameter>) -> Result<()> {
Ok(())
}
}Required Associated Types§
Required Methods§
Sourcefn get_parameters(&self) -> HashMap<String, PluginParameter>
fn get_parameters(&self) -> HashMap<String, PluginParameter>
Get algorithm-specific parameters
Returns a map of all configurable parameters for this algorithm. This enables introspection and parameter tuning.