Skip to content

MLflow API ​

python
from sklearn_genetic.mlflow_log import MLflowConfig

Requires MLflow: pip install sklearn-genetic-opt[mlflow].

MLflowConfig ​

Configures MLflow logging for a GASearchCV or GAFeatureSelectionCV run. Pass an instance to the log_config parameter of the search estimator.

The logger opens a run for each fresh candidate evaluation and writes candidate parameters and the CV objective as score. The runs are nested only when an active parent is present; fit does not itself open a parent.

python
MLflowConfig(
    tracking_uri,
    experiment,
    run_name,
    save_models=False,
    registry_uri=None,
    tags=None,
)

Parameters ​

ParameterTypeDefaultDescription
tracking_uristr—Address of the MLflow tracking server (e.g., "http://localhost:5000")
experimentstr—Name of the MLflow experiment. Created if it doesn't exist
run_namestr—Name used for each candidate run
save_modelsboolFalseLog the configured candidate estimator, not one of the fitted CV-fold clones
registry_uristrNoneAddress of the MLflow model registry server
tagsdictNoneTags applied to the active run when the configuration is constructed; with no active run, MLflow can start one

Usage ​

python
from sklearn_genetic.mlflow_log import MLflowConfig

mlflow_config = MLflowConfig(
    tracking_uri="http://localhost:5000",
    experiment="my-experiment",
    run_name="RF hyperparameter search",
    save_models=False,
)

search = GASearchCV(
    estimator=your_estimator,
    param_grid=your_param_grid,
    cv=your_cv,
    scoring="roc_auc",
    log_config=mlflow_config,  # <-- pass here
)

search.fit(X_train, y_train)

To group candidate runs, explicitly start a parent run in the same experiment around fit. To save a fitted model, log search.best_estimator_ after a successful refit. The runnable recipe uses a local SQLite database.

See Also ​

Released under the MIT License.