Skip to content

Create Leaderboard.py #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions panels/Leaderboard/Leaderboard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
%pip install tabulate
import streamlit as st
import pandas as pd
from comet_ml import API, ui
from comet_ml.api import Metadata, Parameter, Tag

# Initialize Comet API
api = API()
workspace = api.get_panel_workspace()
project_name = api.get_panel_project_name()

# Simple title
st.title("Experiment Leaderboard")
st.markdown("#### by Metric")

# Get available metrics and select one + define objective
available_metrics = api.get_panel_metrics_names()
selected_metric = st.sidebar.selectbox("Select a metric:", available_metrics)
objective = st.sidebar.selectbox("Objective Function:", ["max","min"]) # Change this to "min" for minimization

# Fetch experiment data
experiments = api.get_experiments(workspace, project_name=project_name)
experiment_keys = [exp.key for exp in experiments]

if experiment_keys and selected_metric:
# Fetch the selected metric data for all experiments
df = api.get_metrics_df(experiment_keys, [selected_metric])
# st.table(df)

# Find best metric per experiment
if objective == "max":
best_per_experiment = df.groupby("experiment_name")[selected_metric].max().reset_index()
else:
best_per_experiment = df.groupby("experiment_name")[selected_metric].min().reset_index()

# Merge to get experiment_key for URL generation
best_per_experiment = best_per_experiment.merge(
df[['experiment_name', 'experiment_key']], on='experiment_name', how='left'
).drop_duplicates()

# Sort and get top 10
leaderboard = best_per_experiment.sort_values(
by=selected_metric, ascending=(objective == "min")
).head(10).reset_index(drop=True)

# Create hyperlinks
leaderboard["experiment_name"] = leaderboard.apply(
lambda row: f"[{row['experiment_name']}](https://www.comet.com/{workspace}/{project_name}/{row['experiment_key']})", axis=1
)

# Rename metric column
leaderboard = leaderboard.rename(
columns={
selected_metric: "Best Metric Value",
}
)
leaderboard.drop('experiment_key', axis=1, inplace=True)

# show table
st.table(leaderboard)
Loading