ml_grid.util.validate_parameters

Functions to validate model-specific hyperparameters before grid search.

Functions

validate_knn_parameters(→ Dict[str, Any])

Validates the n_neighbors parameter for KNN classifiers.

validate_XGB_parameters(→ Dict[str, Any])

Validates the max_bin parameter for XGBoost.

validate_parameters_helper(→ Dict[str, Any])

Dispatches to the correct parameter validation function based on algorithm type.

Module Contents

ml_grid.util.validate_parameters.validate_knn_parameters(parameters: Dict[str, Any], ml_grid_object: Any) Dict[str, Any][source]

Validates the n_neighbors parameter for KNN classifiers.

This function ensures that the values for n_neighbors do not exceed the number of samples in the training data. If a value is too large, it is capped at n_samples - 1.

Parameters:
  • parameters (Dict[str, Any]) – The dictionary of parameters to validate.

  • ml_grid_object (Any) – The main pipeline object containing the training data (X_train).

Returns:

The validated parameters dictionary.

Return type:

Dict[str, Any]

ml_grid.util.validate_parameters.validate_XGB_parameters(parameters: Dict[str, Any], ml_grid_object: Any) Dict[str, Any][source]

Validates the max_bin parameter for XGBoost.

This function checks that the max_bin values are greater than or equal to 2, and if not, it sets them to 2.

Parameters:
  • parameters (Dict[str, Any]) – The dictionary of parameters to validate.

  • ml_grid_object (Any) – The main pipeline object (currently unused).

Returns:

The validated parameters dictionary.

Return type:

Dict[str, Any]

ml_grid.util.validate_parameters.validate_parameters_helper(algorithm_implementation: Any, parameters: Dict[str, Any], ml_grid_object: Any) Dict[str, Any][source]

Dispatches to the correct parameter validation function based on algorithm type.

Parameters:
  • algorithm_implementation (Any) – The scikit-learn estimator instance.

  • parameters (Dict[str, Any]) – The dictionary of parameters to validate.

  • ml_grid_object (Any) – The main pipeline object containing training data.

Returns:

The validated parameters dictionary.

Return type:

Dict[str, Any]