微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

生存数据的右删失可视化

如何解决生存数据的右删失可视化

我想知道是否有一种方法可以生成这样的图表

enter image description here

使用生存数据。例如假设我们有这个数据框

d = {'time_in_weeks': [0,10,20,30,50,170],'failure_status': [0,1,1]}

df = pd.DataFrame(data=d)

我们将如何创建后一个图表?

解决方法

import seaborn as sns
import pandas as pd
d = {'time_in_weeks': [0,10,20,30,50,170],'failure_status': [0,1,1]}

这可能是一个好的开始

df = pd.DataFrame(data=d)
df['marker'] = df['failure_status'].map({0:'o',1:'x'})


for x in df.marker.unique():
    t = df.loc[df['marker']==x]
    g = sns.scatterplot(data=t,x='time_in_weeks',y=t.index.tolist(),marker=x,s=100,color='black')

for index,row in df.iterrows():
    g.hlines(y=index,xmin=0,xmax=row['time_in_weeks'],linewidth=2,color='black')

enter image description here

,

lifelines 内置了这个:https://lifelines.readthedocs.io/en/latest/lifelines.plotting.html#lifelines.plotting.plot_lifetimes

from lifelines.plotting import plot_lifetimes
plot_lifetimes(df['time_in_weeks'],df['failure_status'],event_observed_color="k",event_censored_color="k")

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。