Skip to content

Instantly share code, notes, and snippets.

@Marshall-Hallenbeck
Created August 27, 2024 13:37
Show Gist options
  • Save Marshall-Hallenbeck/c7c50c2e704b56d0b3bc8427ecbcd6e6 to your computer and use it in GitHub Desktop.
Save Marshall-Hallenbeck/c7c50c2e704b56d0b3bc8427ecbcd6e6 to your computer and use it in GitHub Desktop.
# Comet Python Panels BETA, full documentation available at:
# https://www.comet.com/docs/v2/guides/comet-ui/experiment-management/visualizations/python-panel/
from comet_ml import API, ui
import matplotlib.pyplot as plt
# Get available metrics
api = API()
metrics = api.get_panel_metrics_names()
# Use API to fetch the metric data for all experiments in the panel scope
experiment_keys = api.get_panel_experiment_keys()
if experiment_keys:
metrics = api.get_metrics_for_chart(experiment_keys, ["metrics/precision(B)", "metrics/recall(B)"])
precision = []
recall = []
figure, ax = plt.subplots()
for experiment_key in metrics:
for metric in metrics[experiment_key]["metrics"]:
if metric["metricName"] == "metrics/precision(B)":
precision = metric
elif metric["metricName"] == "metrics/recall(B)":
recall = metric
p = precision["values"]
r = recall["values"]
f1 = [2 * (p[i] * r[i]) * (p[i] + r[i]) for i in range(len(p))]
print(f"Highest F1 is {max(f1):.4} at step {f1.index(max(f1))}")
ax.plot(precision["epochs"], f1)
ui.display(figure)
else:
ui.display("No data to plot")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment