{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Copyright (c) Microsoft Corporation. All rights reserved.\n", "\n", "Licensed under the MIT License." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Automated Machine Learning: Exploring Previous Runs\n", "\n", "In this example we present some examples on navigating previously executed runs. We also show how you can download a fitted model for any previous run.\n", "\n", "Make sure you have executed the [configuration](../configuration.ipynb) before running this notebook.\n", "\n", "In this notebook you will learn how to:\n", "1. List all experiments in a workspace.\n", "2. List all AutoML runs in an experiment.\n", "3. Get details for an AutoML run, including settings, run widget, and all metrics.\n", "4. Download a fitted pipeline for any iteration.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# List all AutoML Experiments in a Workspace" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import logging\n", "import os\n", "import random\n", "import re\n", "\n", "from matplotlib import pyplot as plt\n", "from matplotlib.pyplot import imshow\n", "import numpy as np\n", "import pandas as pd\n", "from sklearn import datasets\n", "\n", "import azureml.core\n", "from azureml.core.experiment import Experiment\n", "from azureml.core.run import Run\n", "from azureml.core.workspace import Workspace\n", "from azureml.train.automl import AutoMLConfig\n", "from azureml.train.automl.run import AutoMLRun" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ws = Workspace.from_config()\n", "experiment_list = Experiment.list(workspace=ws)\n", "\n", "summary_df = pd.DataFrame(index = ['No of Runs'])\n", "pattern = re.compile('^AutoML_[^_]*$')\n", "for experiment in experiment_list:\n", " all_runs = list(experiment.get_runs())\n", " automl_runs = []\n", " for run in all_runs:\n", " if(pattern.match(run.id)):\n", " automl_runs.append(run) \n", " summary_df[experiment.name] = [len(automl_runs)]\n", " \n", "pd.set_option('display.max_colwidth', -1)\n", "summary_df.T" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Diagnostics\n", "\n", "Opt-in diagnostics for better experience, quality, and security of future releases." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from azureml.telemetry import set_diagnostics_collection\n", "set_diagnostics_collection(send_diagnostics = True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# List AutoML runs for an experiment\n", "Set `experiment_name` to any experiment name from the result of the Experiment.list cell to load the AutoML runs." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "experiment_name = 'automl-local-classification' # Replace this with any project name from previous cell.\n", "\n", "proj = ws.experiments[experiment_name]\n", "summary_df = pd.DataFrame(index = ['Type', 'Status', 'Primary Metric', 'Iterations', 'Compute', 'Name'])\n", "pattern = re.compile('^AutoML_[^_]*$')\n", "all_runs = list(proj.get_runs(properties={'azureml.runsource': 'automl'}))\n", "automl_runs_project = []\n", "for run in all_runs:\n", " if(pattern.match(run.id)):\n", " properties = run.get_properties()\n", " tags = run.get_tags()\n", " amlsettings = eval(properties['RawAMLSettingsString'])\n", " if 'iterations' in tags:\n", " iterations = tags['iterations']\n", " else:\n", " iterations = properties['num_iterations']\n", " summary_df[run.id] = [amlsettings['task_type'], run.get_details()['status'], properties['primary_metric'], iterations, properties['target'], amlsettings['name']]\n", " if run.get_details()['status'] == 'Completed':\n", " automl_runs_project.append(run.id)\n", " \n", "from IPython.display import HTML\n", "projname_html = HTML(\"