#[non_exhaustive]pub struct BayesSearchCV { /* private fields */ }Expand description
Bayesian hyperparameter optimization with cross-validation.
Uses a Tree-structured Parzen Estimator (TPE) to model the objective function and focus evaluations on the most promising hyperparameter combinations.
§Algorithm
- Evaluate
n_initialrandom samples to bootstrap the surrogate model. - For each remaining iteration, split observed results at the
gammaquantile into “good” and “bad” groups. - Build factored 1D kernel density estimates for each group.
- Draw 100 random candidates and pick the one maximizing
l(x) / g(x). - Evaluate the chosen candidate and add it to the history.
§Examples
use scry_learn::prelude::*;
use scry_learn::search::*;
let mut space = ParamSpace::new();
space.insert("max_depth".into(), ParamDistribution::IntUniform { low: 2, high: 10 });
let result = BayesSearchCV::new(DecisionTreeClassifier::new(), space)
.n_iter(20)
.cv(3)
.fit(&data)
.unwrap();
println!("Best score: {:.3}", result.best_score());Implementations§
Source§impl BayesSearchCV
impl BayesSearchCV
Sourcepub fn new(model: impl Tunable + 'static, param_space: ParamSpace) -> Self
pub fn new(model: impl Tunable + 'static, param_space: ParamSpace) -> Self
Create a Bayesian search over the given model and parameter space.
Defaults: 30 iterations, 10 initial random samples, gamma 0.25, 5-fold CV, accuracy scorer, seed 42, non-stratified.
Sourcepub fn n_initial(self, n: usize) -> Self
pub fn n_initial(self, n: usize) -> Self
Set the number of initial random exploration samples (default: 10).
Sourcepub fn gamma(self, gamma: f64) -> Self
pub fn gamma(self, gamma: f64) -> Self
Set the quantile threshold for splitting good/bad observations (default: 0.25).
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 Bayesian optimization 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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BayesSearchCV
impl !RefUnwindSafe for BayesSearchCV
impl !Send for BayesSearchCV
impl !Sync for BayesSearchCV
impl Unpin for BayesSearchCV
impl UnsafeUnpin for BayesSearchCV
impl !UnwindSafe for BayesSearchCV
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
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>
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>
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