Skip to content

Instantly share code, notes, and snippets.

@jayhuang75
Created December 21, 2021 03:35
Show Gist options
  • Select an option

  • Save jayhuang75/5053853a6e0fa704feba26980414018e to your computer and use it in GitHub Desktop.

Select an option

Save jayhuang75/5053853a6e0fa704feba26980414018e to your computer and use it in GitHub Desktop.
go-train-delay-ml-pipeline-lr
async fn linear_regression_model_build(
&self,
x: &DenseMatrix<f64>,
y: &Vec<f64>,
) -> Result<String, AppError> {
// train split
let (x_train, _, y_train, _) = train_test_split(x, y, 0.3, true);
// model
let linear_regression_model =
LinearRegression::fit(&x_train, &y_train, Default::default())?;
let file_name = format!(
"./models/go_train_delay_lr_{}.model",
chrono::offset::Utc::now().date().to_string()
);
// Save the model
let linear_regression_model_bytes = bincode::serialize(&linear_regression_model)?;
File::create(file_name.clone())
.and_then(|mut f| f.write_all(&linear_regression_model_bytes))?;
Ok(file_name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment