{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# MLflow Tutorial: Tracking & Model Registry\n",
        "Xenors practice notebook. Run each cell and compare the output with the tutorial page.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Log a parameter, metric and model artifact\n",
        "A useful run records enough context to reproduce the result, not only the final score.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import mlflow\n",
        "with mlflow.start_run():\n",
        "    mlflow.log_param('max_depth',4)\n",
        "    mlflow.log_metric('f1',0.83)\n",
        "    mlflow.log_text('training complete','notes.txt')\n",
        "    print(mlflow.active_run().info.run_id)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Expected/checkpoint**\n",
        "```text\n<run-id>\n```\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Compare runs programmatically\n",
        "Ranking runs is only useful when the validation split and metric definition are consistent.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "runs = mlflow.search_runs(order_by=['metrics.f1 DESC'])\n",
        "print(runs[['run_id','params.max_depth','metrics.f1']].head())\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Expected/checkpoint**\n",
        "```text\nrun_id ... max_depth ... f1\n```\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.x"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}