rs_ml/transformer/
mod.rs

1//! Functionality to transform and scale data.
2
3use crate::Estimator;
4
5pub mod embedding;
6pub mod scalers;
7
8/// Generic trait to transform data.
9pub trait Transformer<Input, Output> {
10    /// Transform input data based on previously fitted data
11    fn transform(&self, input: &Input) -> Option<Output>;
12}
13
14/// Provided trait on estimators that emit a transfomer
15pub trait FitTransform<Input, Output, T: Transformer<Input, Output>>:
16    Estimator<Input, Estimator = T>
17{
18    /// Fit and transform data in one operation. Useful if you don't need to use the fitted transformer
19    /// multiple times.
20    fn fit_transform(&self, input: &Input) -> Option<Output> {
21        let transfomer = self.fit(input)?;
22        transfomer.transform(input)
23    }
24}
25
26impl<Input, Output, T: Transformer<Input, Output>, E: Estimator<Input, Estimator = T>>
27    FitTransform<Input, Output, T> for E
28{
29}