#[non_exhaustive]pub struct GridSearchCV { /* private fields */ }Expand description
Exhaustive search over a hyperparameter grid with cross-validation.
Tries every combination in the grid, evaluates each with k-fold CV, and reports the best-performing parameter set.
§Examples
ⓘ
use scry_learn::prelude::*;
use scry_learn::search::*;
let mut grid = ParamGrid::new();
grid.insert("max_depth".into(), vec![
ParamValue::Int(2), ParamValue::Int(4), ParamValue::Int(8),
]);
let result = GridSearchCV::new(DecisionTreeClassifier::new(), grid)
.cv(5)
.scoring(accuracy)
.fit(&data)
.unwrap();
println!("Best: {:?} → {:.3}", result.best_params(), result.best_score());Implementations§
Source§impl GridSearchCV
impl GridSearchCV
Sourcepub fn new(model: impl Tunable + 'static, grid: ParamGrid) -> Self
pub fn new(model: impl Tunable + 'static, grid: ParamGrid) -> Self
Create a grid search over the given model and parameter grid.
Defaults: 5-fold CV, accuracy scorer, seed 42, non-stratified.
Sourcepub fn stratified(self, stratified: bool) -> Self
pub fn stratified(self, stratified: bool) -> Self
Enable stratified k-fold CV (default: false).
When true, uses stratified_k_fold
to preserve class proportions in each fold.
Sourcepub fn fit(self, data: &Dataset) -> Result<Self>
pub fn fit(self, data: &Dataset) -> Result<Self>
Run the exhaustive grid search.
Returns self for chained accessor calls.
Sourcepub fn best_params(&self) -> &HashMap<String, ParamValue>
pub fn best_params(&self) -> &HashMap<String, ParamValue>
Sourcepub fn best_score(&self) -> f64
pub fn best_score(&self) -> f64
The best mean CV score achieved.
Sourcepub fn cv_results(&self) -> &[CvResult]
pub fn cv_results(&self) -> &[CvResult]
All evaluated combinations with their scores.
Auto Trait Implementations§
impl Freeze for GridSearchCV
impl !RefUnwindSafe for GridSearchCV
impl !Send for GridSearchCV
impl !Sync for GridSearchCV
impl Unpin for GridSearchCV
impl UnsafeUnpin for GridSearchCV
impl !UnwindSafe for GridSearchCV
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more