use ruthril::core::statistics::Statistics;
pub trait Model {
type Input;
type Output;
type Error;
fn train(&mut self, data: &[Self::Input], targets: &[Self::Output]) -> Result<(), Self::Error>;
fn predict(&self, input: &Self::Input) -> Result<Self::Output, Self::Error>;
fn validate(&self, data: &[Self::Input], targets: &[Self::Output]) -> Result<f64, Self::Error>;
fn calculate_accuracy(&self, predictions: &[f64], targets: &[f64]) -> Option<f64> {
if predictions.len() != targets.len() {
return None;
}
let errors: Vec<f64> = predictions.iter()
.zip(targets.iter())
.map(|(pred, target)| (pred - target).abs())
.collect();
Statistics::mean(&errors)
}
}