Spaces:
Runtime error
Runtime error
| 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 | |
| } | |