Skip to content

RandomizedSearchRegressor

Module: strata.model_selection • Kind: struct • Traits: Copyable, Movable, Regressor
Source: strata/model_selection/randomized_search.mojo

struct RandomizedSearchRegressor[ModelType: Regressor, feat_dtype: DType = DType.float64, target_dtype: DType = DType.float64](Copyable, Movable, Regressor)
from strata.model_selection import RandomizedSearchRegressor

Randomized hyperparameter search for regression models.

Evaluates a random subset of the supplied candidate configurations rather than the full grid, trading exhaustive coverage for a fixed search budget.


def __init__(
out self,
var candidates: List[Self.ModelType],
n_iter: Int = 10,
cv: Int = 5,
scoring: String = "r2",
refit: Bool = True,
random_state: Int = 42,
)

Initializes the randomized search regressor cross-validator.

Argument Type Description
candidates — Pool of candidate model configurations to sample from.
n_iter Int Number of candidates to evaluate, clamped to the pool size.
cv Int Number of cross-validation folds.
scoring String Scoring metric name.
refit Bool Whether to refit the best model on the complete dataset.
random_state Int Seed controlling which candidates are sampled.

Method Description
RandomizedSearchRegressor.fit() Cross-validates a random subset of candidates and fits the best one.
RandomizedSearchRegressor.predict() Predicts targets using the best discovered model configuration.

def fit[in_feat_dtype: DType, in_target_dtype: DType](
mut self,
X: Matrix[in_feat_dtype],
y: List[Scalar[in_target_dtype]],
)
def fit[feat_dtype: DType, target_dtype: DType](
mut self,
dataset: Dataset[feat_dtype, target_dtype],
)

Overload Note: This method accepts either standard (X, y) inputs or a unified dataset: Dataset container.

Cross-validates a random subset of candidates and fits the best one.

Parameter Type Description
X Matrix[in_feat_dtype] Feature training matrix.
y List[Scalar[in_target_dtype]] Target values.
dataset Dataset[feat_dtype, target_dtype] Dataset container holding feature matrix and targets. (Can be provided alternatively in place of (X, y))

def predict[in_feat_dtype: DType](
self,
X: Matrix[in_feat_dtype],
) -> List[Scalar[in_feat_dtype]]
def predict[feat_dtype: DType, target_dtype: DType](
self,
dataset: Dataset[feat_dtype, target_dtype],
) -> List[Scalar[feat_dtype]]

Overload Note: This method accepts either standard (X, y) inputs or a unified dataset: Dataset container.

Predicts targets using the best discovered model configuration.

Parameter Type Description
X Matrix[in_feat_dtype] Feature matrix.
dataset Dataset[feat_dtype, target_dtype] Dataset container holding feature matrix and targets. (Can be provided alternatively in place of (X, y))

Returns: List[Scalar[in_feat_dtype]]