修改后的Bland–Altman图在Seaborn中

我们的实验室使用我们PI称为“修改后的Bland–Altman图”来分析回归质量。我使用Seaborn编写的代码只能处理离散数据,我希望能将其推广到更广泛的应用。

Bland–Altman图比较两个测量值之间的差异与它们的平均值。所谓的“修改”是指x轴不再是平均值,而是真实值。y轴是预测值与真实值之间的差异。实际上,修改后的B–A图可以被视为从y=x线的残差图——即predicted=truth线的残差图。


生成此图的代码以及一个示例如下所示。

def modified_bland_altman_plot(predicted, truth):    predicted = np.asarray(predicted)    truth = np.asarray(truth, dtype=np.int)  # np.int是用于stripplot的临时解决方案    diff = predicted - truth    ax = sns.stripplot(truth, diff, jitter=True)    ax.set(xlabel='truth', ylabel='difference from truth', title="Modified Bland-Altman Plot")    # 在0处绘制一条水平线    ax.axhline(0, ls=":", c=".2")    return ax

Modified Bland–Altman plot

诚然,这个例子显示了预测中的严重偏差,表现为向下的斜率。


我对以下两点感到好奇:

  1. 这些“修改后的Bland–Altman图”是否有公认的名称?
  2. 如何为非离散数据创建这些图?我们使用stripplot,它需要离散数据。我知道seaborn有residplot函数,但它不接受自定义函数来测量残差的线,例如predicted=true。相反,它是从它计算的最佳拟合线来测量残差的。

回答:

看起来你在这里需要的是一个标准的散点图:

enter image description here

import matplotlib.pyplot as pltimport numpy as np; np.random.seed(1)def modified_bland_altman_plot(predicted, truth):    predicted = np.asarray(predicted)    truth = np.asarray(truth)     diff = predicted - truth    fig, ax = plt.subplots()    ax.scatter(truth, diff, s=9, c=truth, cmap="rainbow")    ax.set_xlabel('truth')    ax.set_ylabel('difference from truth')    ax.set_title("Modified Bland-Altman Plot")    # 在0处绘制一条水平线    ax.axhline(0, ls=":", c=".2")    return axx = np.random.rayleigh(scale=10, size=201)y = np.random.normal(size=len(x))+10-x/10.modified_bland_altman_plot(y, x)plt.show()

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注