skip to content

With mlflow.autolog() enabled for a scikit-learn regressor, what does MLflow record on its own, and what must you still log yourself?

level: middleimportance: should knowfreq 15%

answer

  1. patched at fit()
  2. get_params(deep=True)
  3. training_ prefix means in-sample
  4. post-training sklearn.metrics calls
  5. max_tuning_runs keeps five children

basics

~20 s

On fit(), scikit-learn autologging records the estimator's get_params, scores computed on the training data, class-name tags and the fitted model with a signature. A held-out score your own code computes, and settings outside the estimator, you log yourself.

solid answer

~40 s

`mlflow.autolog()` patches `fit()`: it logs every parameter from `get_params(deep=True)` (pipeline steps included), `training_score` plus regression metrics such as `training_mean_squared_error` and `training_r2_score` computed on the data passed to `fit()`, the estimator's class name as tags, and the fitted model as an MLflow Model with a signature — input examples only with `log_input_examples=True`. Those `training_*` numbers are in-sample, so they cannot show that one run generalises better. A later call to a `sklearn.metrics` function on the model's predictions is captured as a post-training metric named after the function and the prediction input's variable, such as `mean_squared_error_X_val` — but only if autologging was enabled before that function was imported and the predictions were not copied or sliced. Business metrics computed by your own code, and settings outside the estimator, still need `log_metric`, `log_param` or tags.

go deeper

for a junior

Recall what autologging adds for scikit-learn: the estimator's params, training metrics, class-name tags and the fitted model with a signature.

for a middle

Explain where each logged number comes from — the fit data versus later metric calls — the post-training key format, and the search estimators' parent and child runs.

for a senior

Show the silent gaps: in-sample metrics mistaken for validation, metric functions imported too early, sliced predictions, five child runs out of forty, and values autolog never sees.

for a principal

Decide what a team leaves to autologging and what it logs explicitly, so the metric used for comparisons is defined once and not inferred from integration defaults.

## What autologging is **Autologging** is MLflow's way of recording a training run without explicit log calls. `mlflow.autolog()` enables it for every supported library that is installed, as each one is imported; library-specific calls such as `mlflow.sklearn.autolog()` do the same for one library, and their settings take precedence over the generic call. The integration **patches the training entry point** — for scikit-learn, `fit()`, `fit_predict()` and `fit_transform()` — and logs when that call runs. If a run is already active, autologged data goes into it (the default `exclusive=False`); otherwise the integration creates a run for the fit. The switches that matter most: - `disable=True` turns autologging off — for every integration from `mlflow.autolog`, or for one library from its own function. - `exclusive=True` keeps autologged content out of runs you opened yourself. - `silent=True` suppresses autologging's own event logs and warnings. - `extra_tags` adds tags to every run autologging creates. - `exclude_flavors` skips named integrations while enabling the rest. ## What scikit-learn autologging records | Kind | What is logged | |---|---| | Params | Everything from `estimator.get_params(deep=True)` — for a `Pipeline`, every step's parameters too | | Metrics | `training_score` from `estimator.score`, and for a regressor `training_mean_squared_error`, `training_root_mean_squared_error`, `training_mean_absolute_error`, `training_r2_score` | | Tags | The estimator's class name and fully qualified class name | | Artifacts | The fitted estimator as an MLflow Model with the scikit-learn flavor, and a signature | Generic switches control the model part: `log_models=True`, `log_model_signatures=True`, `log_input_examples=False` and `log_datasets=True` are the defaults. Signatures and input examples are attributes of the logged model, so turning `log_models` off drops them too. The **training metrics are computed on the data passed to `fit()`**. They are in-sample numbers: useful as a sanity check, useless for showing that one configuration generalises better than another. ## Post-training metrics and their limits With `log_post_training_metrics=True` (the default), MLflow also captures **metric calls made after training**: `model.score` and the functions in `sklearn.metrics`, applied to a model's predictions. The key is `{metric_name}[-{call_index}]_{dataset_name}`, where the dataset name is the variable passed to `predict` — so `preds = model.predict(X_val)` then `mean_squared_error(y_val, preds)` becomes `mean_squared_error_X_val`. A `metric_info.json` artifact records the call that produced each one. The documented limits: 1. Autologging must be enabled **before** the metric functions are imported from `sklearn.metrics`; functions imported earlier are not patched. 2. Only the **original prediction object** returned by `predict`, `predict_proba`, `predict_log_proba` or `transform` is mapped to the run; a copy or a slice of it is not. 3. A custom scorer not built on `sklearn.metrics` is not captured. ## Parameter search estimators For `GridSearchCV` and `RandomizedSearchCV`, autologging creates a **parent run** (the search estimator's params, the best combination, the fitted search and best estimator, and a CSV of search results) and **child runs** with each combination's params and cross-validated test score. `max_tuning_runs=5` by default, so only the **five best-ranked** combinations by `rank_test_score` get child runs; `max_tuning_runs=None` creates one per combination. The internal `fit()` calls the search makes on its child estimators are not logged separately. ## Other libraries, briefly - **XGBoost and LightGBM**: parameters passed to `xgboost.train` / `lightgbm.train`, the user-specified evaluation metrics, the model with a signature and feature importance; with early stopping, the metrics at the best iteration are logged as an extra step. - **Keras**: training and validation loss, user-specified metrics, `fit()` parameters, optimizer name and learning rate, `EarlyStopping` settings, and TensorBoard logs at the end. The callback API itself is Keras's. ## What autologging cannot know - The held-out score computed by your own code — a NumPy expression, a per-store weighted error, a business metric. - Configuration that never reaches the estimator: the feature window, the store subset, which data snapshot was read (beyond what dataset logging captures). - Why the run exists — the hypothesis, the ticket, the comparison it belongs to. Tags and `mlflow.note.content` are the place for that. There is a subtler trap in comparisons. A post-training metric's key embeds the **variable name** of the prediction input, so one script's `mean_squared_error_X_val` and another's `mean_squared_error_X_valid` are different metrics, and a query ordering by one silently drops runs that only have the other. A ranking that depends on how someone named a variable is fragile. So the reliable pattern is: autolog for the boilerplate, plus explicit `log_metric` for the one validation number the team ranks on, and `log_param` or tags for the settings around the estimator.

  • A scikit-learn GridSearchCV over 40 combinations shows only five child runs in MLflow. Why?
    Autologging's `max_tuning_runs` defaults to 5, so child runs are created only for the five best combinations by `rank_test_score`; the parent still holds the full search-results CSV. Pass `max_tuning_runs=None` to `mlflow.sklearn.autolog` for one child run per combination.
  • A validation RMSE computed with NumPy on the predictions never appears in the run. Why, and what do you do?
    Post-training capture only patches `model.score` and `sklearn.metrics` functions applied to the original prediction object. Arithmetic in NumPy is invisible to it. Log the number explicitly with `mlflow.log_metric("val_rmse", value)` inside the run, ideally with a key the whole team ranks on.
  • Preprocessing uses scikit-learn but training uses another library. How do you stop autologging the scikit-learn steps?
    Disable that integration and keep the rest: `mlflow.sklearn.autolog(disable=True)` followed by `mlflow.autolog()`, or call only the training library's own autolog function. `mlflow.autolog(exclude_flavors=[...])` also skips named flavors.

  • training_r2_score from autolog shows how the model performs on unseen data
  • Autolog captures any metric my code computes after fit()
  • GridSearchCV autologging creates one child run per combination by default
  • Autolog saves an input example with the model unless you turn it off
  • Enabling autolog after importing sklearn.metrics functions still captures their calls