metrics.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:mimic3-benchmarks 作者: YerevaNN 项目源码 文件源码
def print_metrics_regression(y_true, predictions, verbose=1):
    predictions = np.array(predictions)
    predictions = np.maximum(predictions, 0).flatten()
    y_true = np.array(y_true)

    y_true_bins = [get_bin_custom(x, CustomBins.nbins) for x in y_true]
    prediction_bins = [get_bin_custom(x, CustomBins.nbins) for x in predictions]
    cf = metrics.confusion_matrix(y_true_bins, prediction_bins)
    if verbose:
        print "Custom bins confusion matrix:"
        print cf

    kappa = metrics.cohen_kappa_score(y_true_bins, prediction_bins,
                                      weights='linear')
    mad = metrics.mean_absolute_error(y_true, predictions)
    mse = metrics.mean_squared_error(y_true, predictions)
    mape = mean_absolute_percentage_error(y_true, predictions)

    if verbose:
        print "Mean absolute deviation (MAD) =", mad
        print "Mean squared error (MSE) =", mse
        print "Mean absolute percentage error (MAPE) =", mape
        print "Cohen kappa score =", kappa

    return {"mad": mad,
            "mse": mse,
            "mape": mape,
            "kappa": kappa}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号