{ "cells": [ { "cell_type": "markdown", "id": "061ee14e-0fab-4eaf-93db-b445b743174c", "metadata": {}, "source": [ "# Dashboard\n", "\n", "The dashboard is used to combine multiple `rubicon_ml` widgets into a sigle, interactive\n", "dashboard. When a `rubicon_ml.viz.ExperimentsTable` is present in the dashboard, it acts\n", "as a controller to select the experiments visible in the other widgets in the dashboard." ] }, { "cell_type": "code", "execution_count": 1, "id": "5be9ae89-279f-4c3c-87e8-ab5ff2de34c6", "metadata": {}, "outputs": [], "source": [ "import random\n", "\n", "import numpy as np\n", "import pandas as pd\n", "\n", "from rubicon_ml import Rubicon\n", "from rubicon_ml.viz import (\n", " DataframePlot,\n", " ExperimentsTable,\n", " MetricCorrelationPlot,\n", " MetricListsComparison,\n", ")\n", "from rubicon_ml.viz.dashboard import Dashboard" ] }, { "cell_type": "markdown", "id": "991c951e-184f-4f9d-b83b-95de0df5387c", "metadata": {}, "source": [ "First, we'll create a few experiments and populate them full of parameters, metrics,\n", "and dataframes." ] }, { "cell_type": "code", "execution_count": 2, "id": "039b59fc-709d-48a8-88de-0c97f9966dbf", "metadata": {}, "outputs": [], "source": [ "dates = pd.date_range(start=\"1/1/2010\", end=\"12/1/2020\", freq=\"MS\")\n", "\n", "rubicon = Rubicon(persistence=\"memory\", auto_git_enabled=True)\n", "project = rubicon.get_or_create_project(\"dashboard composition\")\n", "\n", "for i in range(0, 10):\n", " experiment = project.log_experiment()\n", "\n", " experiment.log_parameter(\n", " name=\"is_standardized\",\n", " value=random.choice([True, False]),\n", " )\n", " experiment.log_parameter(name=\"n_estimators\", value=random.randrange(2, 10, 2))\n", " experiment.log_parameter(\n", " name=\"sample\",\n", " value=random.choice([\"A\", \"B\", \"C\", \"D\", \"E\"]),\n", " )\n", "\n", " experiment.log_metric(name=\"accuracy\", value=random.random())\n", " experiment.log_metric(name=\"confidence\", value=random.random())\n", "\n", " experiment.log_metric(\n", " name=\"coefficients\",\n", " value=[random.random() for _ in range(0, 5)],\n", " )\n", " experiment.log_metric(\n", " name=\"stderr\",\n", " value=[random.random() for _ in range(0, 5)],\n", " )\n", "\n", " data = np.array(\n", " [\n", " list(dates),\n", " np.linspace(random.randint(0, 15000), random.randint(0, 15000), len(dates))\n", " ]\n", " )\n", " data_df = pd.DataFrame.from_records(\n", " data.T,\n", " columns=[\"calendar month\", \"open accounts\"],\n", " )\n", "\n", " experiment.log_dataframe(data_df, name=\"open accounts\")" ] }, { "cell_type": "markdown", "id": "4ef7c1dd-6f9a-4ce1-b14a-26d54e000526", "metadata": {}, "source": [ "Now, we can instantiate the `Dashboard` object with the experiments we just logged.\n", "By default, the dashboard will have an `ExperimentsTable` stacked on top of a\n", "`MetricCorrelationPlot`. Selecting an experiment in the experiments table will render\n", "it on the metric correlation plot.\n", "\n", "We can view the dashboard right in the notebook with `show`. The Dash application\n", "itself will be running on http://127.0.0.1:8050/ when running locally. Use the\n", "`serve` command to launch the server directly without rendering the widget in the\n", "current Python interpreter." ] }, { "cell_type": "code", "execution_count": 3, "id": "03945010-f8fa-4d01-9f03-94b52586f8cb", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Dash is running on http://127.0.0.1:8050/\n" ] } ], "source": [ "default_dashbaord = Dashboard(experiments=project.experiments())\n", "default_dashbaord.show()" ] }, { "cell_type": "markdown", "id": "c5eb33cb-2b46-456e-8f99-5574d5353799", "metadata": {}, "source": [ "![default-dashboard](default-dashboard.png \"default dashboard\")" ] }, { "cell_type": "markdown", "id": "08e9ec5f-cff2-46ee-be45-e310d74e51d4", "metadata": {}, "source": [ "To customize a dashboard, we can pass in the widgets we want rendered. Arguments to `widgets`\n", "should be a list of lists of instantiated `rubicon_ml` widgets. Each inner list represents a row in the rendered dashboard. Note that the internal widgets are not instantiated with\n", "experiments. We provide the experiments to the dashboard itself so each widget shares the\n", "same experiments.\n", "\n", "Again, we can use `show` to see our four `rubicon_ml` widgets arranged into a 2x2 dashboard." ] }, { "cell_type": "code", "execution_count": 4, "id": "c46575d2-509f-4c8f-8ccb-1f9043e71627", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Dash is running on http://127.0.0.1:8051/\n" ] } ], "source": [ "Dashboard(\n", " experiments=project.experiments(),\n", " widgets=[\n", " [\n", " ExperimentsTable(is_selectable=True),\n", " MetricCorrelationPlot(selected_metric=\"accuracy\"),\n", " ],\n", " [\n", " \n", " MetricListsComparison(column_names=[f\"var_00{i}\" for i in range(0, 5)]),\n", " DataframePlot(dataframe_name=\"open accounts\"),\n", " ],\n", " ],\n", ").show()" ] }, { "cell_type": "markdown", "id": "0c6b0623-d4a0-4159-80fc-e97e219d2234", "metadata": {}, "source": [ "![full-dashboard](full-dashboard.png \"full dashboard\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" } }, "nbformat": 4, "nbformat_minor": 5 }