#!/usr/bin/env python
# coding: utf-8
#
#

#
#
# # Welcome to the `rubicon_ml` examples!
#
# Try out `rubicon_ml` for yourself without any setup required! If you'd like to learn more about
# `rubicon_ml` before getting started, check out the
# [documentation on GitHub](https://capitalone.github.io/rubicon-ml/).
# ## Exploring an existing `rubicon_ml` project
#
# Below we'll explore an existing `rubicon_ml` project using the built-in visualization module to
# inspect and analyze some previously trained models.
#
# [This GitHub repository](https://github.com/ryanSoley/experimenting-with-rubicon) contains
# a simple classification model in `my_model/my_model.py`. Over three commits, three
# different types of models were used to classify species of penguins by
# some physical characteristics. During each model run, `rubicon_ml` was used to log the results.
#
# The `rubicon_ml` logs from that project have been copied locally into this Binder session. In
# a more realistic use case, you may be reading shared `rubicon_ml` logs from S3.
#
# There are a number of questions you'll be able to answer by using the experiment table below:
# * What were the input parameters and output metrics of each model run?
# * What type of model did each run use?
# * Where is the source code that was used to generate each model run's logs?
# * Which model and input parameters produced the best results?
#
# **Note: `default_server_url` should match the root of the URL currently in your address
# bar - change as necessary.**
# In[ ]:
import os
from rubicon_ml import Rubicon
from rubicon_ml.viz import ExperimentsTable
default_server_url = "https://hub.gke2.mybinder.org/"
# default_server_url = "https://hub-binder.mybinder.ovh"
port = 8050
requests_pathname_prefix = f"{os.environ['JUPYTERHUB_SERVICE_PREFIX']}proxy/{port}/"
dash_kwargs = {"requests_pathname_prefix": requests_pathname_prefix}
run_server_kwargs = {"proxy": f"http://127.0.0.1:{port}::{default_server_url}", "port": port}
rubicon = Rubicon(persistence="filesystem", root_dir=f"{os.getcwd()}/rubicon-root")
project = rubicon.get_project(name="Classifying Penguins")
experiments_table = ExperimentsTable(experiments=project.experiments())
experiments_table.show(dash_kwargs=dash_kwargs, run_server_kwargs=run_server_kwargs)
# ## Running Other `rubicon_ml` Examples
#
# You can run any of the examples from the `rubicon_ml` docs in this Binder session! These examples
# will show how to log your own projects and experiments, share and visualize them. Run the cell below
# to generate the links to these examples for the current Binder session.
#
# **Note: The examples in the "Visualizations" section will need to be manually updated to provide
# the `show` and `serve` methods the same `dash_kwargs` and `run_server_kwargs` arguments as the cell
# above.**
# In[ ]:
session_base_url = os.path.dirname(os.path.dirname(os.path.dirname((
default_server_url + requests_pathname_prefix
))))
print(f"Quick Look: \t{session_base_url}/tree/notebooks/quick-look")
print(f"Examples: \t{session_base_url}/tree/notebooks/logging-examples")
print(f"Integrations: \t{session_base_url}/tree/notebooks/integrations")
print(f"Visualizations: {session_base_url}/tree/notebooks/viz")