use crate::error::Error;
use crate::serialization::types::{ModelType, SerializedModel};
use serde::Serialize;
pub trait ModelSave: Serialize {
fn save(&self, path: &str) -> Result<(), Error> {
self.save_with_name(path, None)
}
fn save_with_name(&self, path: &str, name: Option<String>) -> Result<(), Error>;
fn model_type() -> ModelType;
}
pub trait ModelLoad: Sized {
fn load(path: &str) -> Result<Self, Error>;
fn from_serialized(model: SerializedModel) -> Result<Self, Error>;
fn model_type() -> ModelType;
}
#[cfg(test)]
mod tests {
use crate::serialization::ModelType;
#[test]
fn test_model_type_display() {
assert_eq!(ModelType::OLS.to_string(), "OLS");
assert_eq!(ModelType::Ridge.to_string(), "Ridge");
assert_eq!(ModelType::Lasso.to_string(), "Lasso");
assert_eq!(ModelType::ElasticNet.to_string(), "ElasticNet");
assert_eq!(ModelType::WLS.to_string(), "WLS");
assert_eq!(ModelType::LOESS.to_string(), "LOESS");
}
}