Execute this notebook to test out the different metrics.
import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact # pip install ipywidgets
import modelskill.metrics as mtr
metrics = [mtr.bias, mtr.max_error, mtr.rmse, mtr.urmse, mtr.mae, mtr.mape,
mtr.mef, mtr.si, mtr.cc, mtr.spearmanr, mtr.r2, mtr.nse, mtr.willmott, mtr.lin_slope, mtr.kge, mtr.ev]
n = 50
x = np.linspace(0.0, 6.0, num=n)
y_obs = 2.0+3*np.sin(x/2.4)
noise_vec = np.random.randn(n)
noise_vec = noise_vec - noise_vec.mean()
def plot_metrics(bias, noise_level, fixed_y_axis=True):
y_mod = y_obs + bias + noise_level*noise_vec
plt.plot(x, y_obs, 'r.-', label="obs")
plt.plot(x, y_mod, 'o-', label="model")
plt.title(f"y_model = y_obs + {bias} + {noise_level}*noise")
ymax = max(max(y_obs),max(y_mod))
ymin = min(min(y_obs), min(y_mod))
if fixed_y_axis:
ymax = 8
ymin = 1
ystep = 1.2*(ymax - ymin)/len(metrics)
ypos = ymax + 0.5
for m in metrics:
plt.text(6.5, ypos, f"{m.__name__}:")
plt.text(8.0, ypos, f"{m(y_obs,y_mod):.4f}")
ypos = ypos - ystep
plt.legend(loc=2)
if fixed_y_axis:
plt.ylim(ymin, ymax)
plt.show()
interact(plot_metrics, bias = (-1,3,0.1), noise_level=(0,2,0.05));