Charles Kabui
commited on
Commit
·
b111458
1
Parent(s):
48eb0c5
training
Browse files- .gitignore +1 -0
- model/README.ipynb +0 -0
- utils/plot_metrics.py +30 -0
.gitignore
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
utils/__pycache__/plot_metrics.cpython-310.pyc
|
model/README.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
utils/plot_metrics.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List, Tuple
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
from matplotlib.axes import Axes
|
4 |
+
import pandas as pd
|
5 |
+
|
6 |
+
def plot_metrics(
|
7 |
+
metrics: List[Tuple[pd.Series, pd.Series, str]] | List[List[Tuple[pd.Series, pd.Series, str]]],
|
8 |
+
remove_na: bool = False,
|
9 |
+
subAxes: Axes = None,
|
10 |
+
title: str = None,
|
11 |
+
xlabel: str = None,
|
12 |
+
ylabel: str = None,
|
13 |
+
figsize=(8, 6)):
|
14 |
+
_, axes = plt.subplots(len(metrics), 1, figsize=(
|
15 |
+
figsize[0], figsize[1] * len(metrics))) if subAxes is None else (None, subAxes)
|
16 |
+
for index, metric in enumerate(metrics):
|
17 |
+
ax = (axes[index] if len(metrics) >
|
18 |
+
1 else axes) if subAxes is None else subAxes
|
19 |
+
if type(metric) is tuple:
|
20 |
+
(x, y, legend) = metric[0:3]
|
21 |
+
color = metric[3] if len(metric) > 3 else 'blue'
|
22 |
+
[x, y] = [x, y] if not remove_na else zip(
|
23 |
+
*[[x_1, y_1] for x_1, y_1 in zip(x, y) if pd.notna(y_1)])
|
24 |
+
ax.plot(x, y, color=color, label=legend)
|
25 |
+
ax.legend()
|
26 |
+
else:
|
27 |
+
plot_metrics(metric, remove_na, ax)
|
28 |
+
plt.title(title)
|
29 |
+
plt.xlabel(xlabel)
|
30 |
+
plt.ylabel(ylabel)
|