#[non_exhaustive]pub struct RandomizedSearchCV { /* private fields */ }Expand description
Randomized search over a hyperparameter grid with cross-validation.
Samples n_iter random combinations from the grid instead of trying
every one — much faster for large grids.
§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(6), ParamValue::Int(8),
]);
let result = RandomizedSearchCV::new(DecisionTreeClassifier::new(), grid)
.n_iter(5)
.cv(3)
.fit(&data)
.unwrap();Implementations§
Source§impl RandomizedSearchCV
impl RandomizedSearchCV
Sourcepub fn new(model: impl Tunable + 'static, grid: ParamGrid) -> Self
pub fn new(model: impl Tunable + 'static, grid: ParamGrid) -> Self
Create a randomized search with n_iter random samples.
Defaults: 10 iterations, 5-fold CV, accuracy scorer, seed 42, non-stratified.
Sourcepub fn n_iter(self, n: usize) -> Self
pub fn n_iter(self, n: usize) -> Self
Set the number of random combinations to try (default: 10).
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 randomized search.
Samples up to n_iter random parameter combinations from the grid.
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 RandomizedSearchCV
impl !RefUnwindSafe for RandomizedSearchCV
impl !Send for RandomizedSearchCV
impl !Sync for RandomizedSearchCV
impl Unpin for RandomizedSearchCV
impl UnsafeUnpin for RandomizedSearchCV
impl !UnwindSafe for RandomizedSearchCV
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