+++ title = "Cross Validation" +++ ```rust // parameters to compare let ratios = vec![0.1, 0.2, 0.5, 0.7, 1.0]; // create a model for each parameter let models = ratios .iter() .map(|ratio| ElasticNet::params().penalty(0.3).l1_ratio(*ratio)) .collect::>(); // get the mean r2 validation score across 5 folds for each model let r2_values = dataset.cross_validate(5, &models, |prediction, truth| prediction.r2(&truth))?; // show the mean r2 score for each parameter choice for (ratio, r2) in ratios.iter().zip(r2_values.iter()) { println!("L1 ratio: {}, r2 score: {}", ratio, r2); } ```