liveBook · Manning

Autologging

As explained in Machine Learning Platform Engineering

Autologging is the automatic recording of model parameters, metrics, artifacts, and related information during machine learning training and evaluation.

Autologging records model parameters, datasets, metrics, models, and plots during training and evaluation without requiring explicit logging for each item. In MLflow, enable it inside a run with one integration-specific call such as mlflow.xgboost.autolog(). section 4.1.2

Use autologging as a baseline, then add manual logging where its defaults do not match the experiment:

  • Log custom metrics explicitly; autologging does not capture them automatically. section 4.1.2
  • Supplement dataset logging when the default array representation should be preserved as a data frame or another format. section 4.1.2
  • Inspect the run for automatically saved parameters, models, datasets, and feature-importance plots. section 4.1.2

XGBoost training run

Start an MLflow run, call mlflow.xgboost.autolog(), train an XGBoost model, and inspect the resulting run. Parameters, datasets, the model, and feature-importance plots appear without separate logging calls. section 4.1.2

Listing 4.6 Using the MLflow autologging functionality
with mlflow.start_run():
       mlflow.xgboost.autolog()        #1


    n_round = 30
    dtrain = xgb.DMatrix(data=X_train, label=y_train.ravel())
    dtest = xgb.DMatrix(data=X_test, label=y_test.ravel())

       params = {
        "objective": "binary:logistic",
        "colsample_bytree": 1,
        "learning_rate": 1,
        "max_depth": 10,
        "subsample": 1,
    }


    model = xgb.train(params, dtrain, n_round)



    ax = xgb.plot_importance(
     model,
     max_num_features=10,
     importance_type="cover"
    )
    fig = ax.figure
    fig.set_size_inches(10, 8)


    pred_train = model.predict(dtrain)
    pred_test = model.predict(dtest)


    hinge_params = {
        "objective": "binary:hinge",
        "colsample_bytree": 1,
        "learning_rate": 1,
        "max_depth": 10,
        "subsample": 1,
    }
    model = xgb.train(hinge_params, dtrain)


    pred_train = model.predict(dtrain)
    pred_test = model.predict(dtest)


    roc_auc_score_train = roc_auc_score(y_train == 1, pred_train)
    roc_auc_score_test = roc_auc_score(y_test == 1, pred_test)
    training_accuracy = accuracy_score(y_train, pred_train)
    test_accuracy = accuracy_score(y_test, pred_test)


           mlflow.log_metric(
      "roc_auc_score_train",
      roc_auc_score_train
    )        #2
    mlflow.log_metric("roc_auc_score_test", roc_auc_score_test)
    mlflow.log_metric("training_accuracy", training_accuracy)
    mlflow.log_metric("test_accuracy", test_accuracy)


    print(f"ROC AUC Score (train): {roc_auc_score_train}\n")
    print(f"ROC AUC Score (test): {roc_auc_score_test}\n")
    print(f"Accuracy (train): {training_accuracy}")
    print(f"Accuracy (test): {test_accuracy}")

Runnable XGBoost autologging configuration and training example. section 4.1.2

How Machine Learning Platform Engineering covers it

How deep it goes
Explains activation, automatically captured data, and manual supplementation, but stops short of implementation internals.
Examples
Uses an XGBoost income-classifier run that produces parameters, datasets, a model, and feature-importance plots.
What it assumes
Assumes a machine learning training run and introduces MLflow-based tracking through an XGBoost integration.
What you can do after
Apply it via MLflow to capture standard training information and supplement custom metrics or formats manually.
How it connects
Connects experiment tracking with model parameters, metrics, artifacts, datasets, model evaluation, and feature importance.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Machine Learning Platform Engineering. The section links point to the parts of the book it draws on.