import logging import numpy as np import math #### Fonctions à modifier !!! def evaluate_hybrid(model,df, trainAttrX, trainImagesX, trainY,sc): logging.info("predicting ...") preds = model.predict([trainAttrX, trainImagesX]) diff = preds.flatten() - trainY percentDiff = (diff / trainY) * 100 absPercentDiff = np.abs(percentDiff) mean = np.mean(absPercentDiff) std = np.std(absPercentDiff) print("avg. FVC: {}, std FVC {}".format(df["FVC"].mean(), df["FVC"].std())) print("mean difference : {:.2f}%, std: {:.2f}%".format(mean, std)) return preds def evaluate_cnn(model,df, trainImagesX, trainY,sc): logging.info("predicting ...") preds = model.predict(trainImagesX) diff = sc.inverse_transform(preds.flatten()) - sc.inverse_transform(trainY) percentDiff = (diff / sc.inverse_transform(trainY)) * 100 absPercentDiff = np.abs(percentDiff) mean = np.mean(absPercentDiff) std = np.std(absPercentDiff) print("avg. FVC: {}, std FVC {}".format(df["FVC"].mean(), df["FVC"].std())) print("mean difference : {:.2f}%, std: {:.2f}%".format(mean, std)) return preds def evaluate_mlp(model,df, trainAttrX, trainY,sc): logging.info("predicting ...") preds = model.predict(trainAttrX) diff = sc.inverse_transform(preds.flatten()) - sc.inverse_transform(trainY) percentDiff = (diff / sc.inverse_transform(trainY)) * 100 absPercentDiff = np.abs(percentDiff) mean = np.mean(absPercentDiff) std = np.std(absPercentDiff) print("avg. FVC: {}, std FVC {}".format(df["FVC"].mean(), df["FVC"].std())) print("mean difference : {:.2f}%, std: {:.2f}%".format(mean, std)) return preds def compute_score(y_true, y_pred, sigma): fvc_pred = y_pred sigma_clip = np.maximum(sigma, 70) delta = np.minimum(abs(y_true - fvc_pred),1000) sq2 = math.sqrt(2) metric = -(delta / sigma_clip)*sq2 - np.log(sigma_clip* sq2) return (np.mean(metric))