Spaces:
Sleeping
Sleeping
File size: 1,174 Bytes
1a0754f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import numpy as np
import xarray as xr # si usas netCDF
# o from netCDF4 import Dataset
# o import csv etc. según tu formato
def evaluate_prediction(pred_file_path, reference_file_path):
"""
pred_file_path: str - Ruta al archivo subido por el participante
reference_file_path: str - Ruta a tu ground-truth, local o en la web
returns: dict - un diccionario con las métricas calculadas
"""
# Ejemplo usando netCDF
pred_data = xr.open_dataset(pred_file_path)
ref_data = xr.open_dataset(reference_file_path)
# Asume que ambos tienen la misma dimensión "wavelength" o algo similar
pred_values = pred_data["spectrum"].values # shape (n_wavelengths,)
ref_values = ref_data["spectrum"].values # shape (n_wavelengths,)
# Calcular MRE por banda
mre = np.abs((pred_values - ref_values) / ref_values)
# MRE medio
mre_mean = mre.mean()
# Otras métricas
rmse = np.sqrt(((pred_values - ref_values)**2).mean())
# Retornar resultados en un dict
return {
"mre_mean": float(mre_mean),
"rmse": float(rmse),
"mre_spectrum": mre.tolist(), # El espectro de MRE completo
}
|