【问题标题】:Modified Bland–Altman plot in SeabornSeaborn 中修改的 Bland-Altman 情节
【发布时间】:2017-05-20 09:39:04
【问题描述】:

我的实验室使用我们的 PI 所称的“改进的 Bland-Altman 图”来分析回归质量。我用 Seaborn 写的代码只处理离散数据,我想概括一下。

Bland–Altman plot 将两个度量之间的差异与其平均值进行比较。 “修改”是 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 is a hack for stripplot
    diff = predicted - truth

    ax = sns.stripplot(truth, diff, jitter=True)
    ax.set(xlabel='truth', ylabel='difference from truth', title="Modified Bland-Altman Plot")

    # Plot a horizontal line at 0
    ax.axhline(0, ls=":", c=".2")

    return ax

诚然,这个例子的预测存在严重的偏差,如下降趋势所示。


我对两件事感到好奇:

  1. 这些“改良的 Bland-Altman 地块”是否有一个普遍接受的名称?
  2. 如何为非离散数据创建这些?我们使用stripplot,它需要离散数据。我知道 seaborn 有 residplot 函数,但它没有为测量残差的线使用自定义函数,例如predicted=true。相反,它会根据计算出的最佳拟合线进行测量。

【问题讨论】:

    标签: python matplotlib plot machine-learning seaborn


    【解决方案1】:

    您似乎正在这里寻找标准散点图:

    import matplotlib.pyplot as plt
    import 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")
    
        # Plot a horizontal line at 0
        ax.axhline(0, ls=":", c=".2")
    
        return ax
    
    x = 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()
    

    【讨论】:

    • 在这种情况下,颜色表示什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-14
    相关资源
    最近更新 更多