pub trait Transformer {
type Config;
fn transform(config: &Self::Config, x: &[Vec<f64>]) -> Vec<Vec<f64>>;
}
pub trait FittableTransformer {
type Config;
type Fitted: Clone + Send + Sync;
fn fit(config: &Self::Config, x: &[Vec<f64>], y: Option<&[String]>) -> Self::Fitted;
fn transform(fitted: &Self::Fitted, x: &[Vec<f64>]) -> Vec<Vec<f64>>;
fn fit_transform(config: &Self::Config, x: &[Vec<f64>], y: Option<&[String]>) -> Vec<Vec<f64>> {
let fitted = Self::fit(config, x, y);
Self::transform(&fitted, x)
}
}
pub trait Classifier {
type Config;
type Fitted: Clone + Send + Sync;
fn fit(config: &Self::Config, x: &[Vec<f64>], y: &[String]) -> Self::Fitted;
fn predict(fitted: &Self::Fitted, x: &[Vec<f64>]) -> Vec<String>;
fn score(fitted: &Self::Fitted, x: &[Vec<f64>], y: &[String]) -> f64 {
let predictions = Self::predict(fitted, x);
let correct = predictions
.iter()
.zip(y.iter())
.filter(|(p, t)| p == t)
.count();
correct as f64 / y.len() as f64
}
}
pub trait DistanceMetric: Clone + Send + Sync {
fn distance(&self, a: &[f64], b: &[f64]) -> f64;
}