pub trait ModelSave: Serialize {
// Required methods
fn save_with_name(
&self,
path: &str,
name: Option<String>,
) -> Result<(), Error>;
fn model_type() -> ModelType;
// Provided method
fn save(&self, path: &str) -> Result<(), Error> { ... }
}Expand description
Trait for saving models to disk.
This trait is implemented by all regression result types that support serialization. Models are saved as JSON with a metadata wrapper.
§Example
ⓘ
let y = vec![2.0, 4.0, 6.0, 8.0];
let x1 = vec![1.0, 2.0, 3.0, 4.0];
let names = vec!["Intercept".into(), "X1".into()];
let model = ols_regression(&y, &[x1], &names).unwrap();
model.save("my_model.json").unwrap();Required Methods§
Sourcefn save_with_name(&self, path: &str, name: Option<String>) -> Result<(), Error>
fn save_with_name(&self, path: &str, name: Option<String>) -> Result<(), Error>
Save the model to a file with a custom name.
The name is stored in the model metadata and can be used to identify the model later.
§Arguments
path- File path to save toname- Optional custom name for the model
Sourcefn model_type() -> ModelType
fn model_type() -> ModelType
Get the model type identifier.
This is used when serializing to store the model type in metadata.
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.