Skip to content

Commit e80cf38

Browse files
authored
Merge pull request #257 from comet-ml/chasefortier-metricbystep-panel
Create Metrics by Step Panel
2 parents 8a69041 + 8d65ac0 commit e80cf38

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from comet_ml import API, ui
2+
import pandas as pd
3+
import streamlit as st
4+
import plotly.express as px
5+
6+
# Get available metrics
7+
api = API()
8+
9+
experiment_keys = api.get_panel_experiment_keys()
10+
all_metric_names = api.get_panel_metrics_names()
11+
12+
all_metrics = st.sidebar.toggle("All Metrics", value=1, help="Display chart for all metrics logged to the project.")
13+
14+
if not all_metrics:
15+
metric_names = st.sidebar.multiselect("Metrics:", all_metric_names, help= "Metrics to display.")
16+
else:
17+
metric_names = all_metric_names
18+
19+
if metric_names:
20+
metrics_df = api.get_metrics_df(
21+
experiment_keys, metrics=metric_names, interpolate=False
22+
)
23+
24+
# Get min and max step and generate step slider
25+
step_max = metrics_df['step'].max()
26+
step_min = metrics_df['step'].min()
27+
28+
slider = st.sidebar.slider("Step:", int(step_min), int(step_max))
29+
30+
# Filter to data for the selected step
31+
step_data = metrics_df.loc[metrics_df['step'] == slider].copy()
32+
33+
# OPTIONAL: if experiment_key is the index, reset it so it's a column
34+
if 'experiment_key' not in step_data.columns:
35+
step_data = step_data.reset_index().rename(columns={'index': 'experiment_key'})
36+
37+
# Plot a bar chart for each metric
38+
for metric in metric_names:
39+
# Skip metrics that might not be present
40+
if metric not in step_data.columns:
41+
continue
42+
43+
metric_df = step_data[['experiment_name', metric]].copy()
44+
45+
fig = px.bar(
46+
metric_df,
47+
x='experiment_name',
48+
y=metric,
49+
title=f"{metric} at step {slider}",
50+
labels={
51+
'experiment_name': 'Experiment',
52+
metric: metric,
53+
}
54+
)
55+
56+
st.plotly_chart(fig, use_container_width=True)

panels/MetricsByStep/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### CompareMaxAccuracyOverTime
2+
3+
The `MetricsByStep` panel is used to compare the value of your metrics at a specific step across all of your experiments using bar charts.
4+
5+
6+
<table>
7+
<tr>
8+
<td>
9+
<img src="https://raw.githubusercontent.com/comet-ml/comet-examples/refs/heads/master/panels/MetricsByStep/metrics-by-step-panel.png"
10+
style="max-width: 300px; max-height: 300px;">
11+
</img>
12+
</td>
13+
</tr>
14+
</table>
15+
16+
#### Python Panel
17+
18+
To include this panel from the github repo, use this code in a Custom Python Panel:
19+
20+
```
21+
%include https://raw.githubusercontent.com/comet-ml/comet-examples/refs/heads/master/panels/MetricsByStep/MetricsByStep.py
22+
```
23+
24+
Or, you can simply [copy the code](https://raw.githubusercontent.com/comet-ml/comet-examples/refs/heads/master/panels/MetricsByStep/MetricsByStep.py) into a custom Python Panel.
25+
26+
27+
225 KB
Loading

0 commit comments

Comments
 (0)