pub trait TransformerPlugin<X, Output = X>:
Plugin
+ Send
+ Sync {
type Fitted: Transform<X, Output> + Send + Sync;
// Required methods
fn fit_transform(&self, x: &X) -> Result<(Self::Fitted, Output)>;
fn transform(&self, fitted: &Self::Fitted, x: &X) -> Result<Output>;
}Expand description
Trait for transformer plugins
This trait defines the interface for data transformation algorithms that can fit to data and then transform new data using the learned transformation.
§Type Parameters
X- The input data typeOutput- The transformed output type (defaults to X)
§Examples
ⓘ
use sklears_core::plugin::{Plugin, TransformerPlugin};
use sklears_core::traits::Transform;
use sklears_core::error::Result;
#[derive(Debug)]
struct StandardScaler {
// scaler parameters
}
struct FittedStandardScaler {
// fitted scaler state
}
impl Transform<Vec<f64>, Vec<f64>> for FittedStandardScaler {
fn transform(&self, x: &Vec<f64>) -> Result<Vec<f64>> {
// transformation implementation
Ok(x.clone())
}
}
impl TransformerPlugin<Vec<f64>, Vec<f64>> for StandardScaler {
type Fitted = FittedStandardScaler;
fn fit_transform(&self, x: &Vec<f64>) -> Result<(Self::Fitted, Vec<f64>)> {
let fitted = FittedStandardScaler {};
let transformed = fitted.transform(x)?;
Ok((fitted, transformed))
}
fn transform(&self, fitted: &Self::Fitted, x: &Vec<f64>) -> Result<Vec<f64>> {
fitted.transform(x)
}
}Required Associated Types§
Required Methods§
Sourcefn fit_transform(&self, x: &X) -> Result<(Self::Fitted, Output)>
fn fit_transform(&self, x: &X) -> Result<(Self::Fitted, Output)>
Fit the transformer to data and return the fitted transformer along with transformed data
This method fits the transformer to the input data and immediately applies the transformation, returning both the fitted transformer and the transformed data.
§Arguments
x- Input data to fit and transform
§Returns
A tuple of (fitted transformer, transformed data) or an error.