當前位置: 首頁>>代碼示例>>Python>>正文


Python lifelines.KaplanMeierFitter方法代碼示例

本文整理匯總了Python中lifelines.KaplanMeierFitter方法的典型用法代碼示例。如果您正苦於以下問題:Python lifelines.KaplanMeierFitter方法的具體用法?Python lifelines.KaplanMeierFitter怎麽用?Python lifelines.KaplanMeierFitter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在lifelines的用法示例。


在下文中一共展示了lifelines.KaplanMeierFitter方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: calib_plot

# 需要導入模塊: import lifelines [as 別名]
# 或者: from lifelines import KaplanMeierFitter [as 別名]
def calib_plot(fu_time, n_bins, pred_surv, time, dead, color, label, error_bars=0,alpha=1., markersize=1., markertype='o'):
	cuts = np.concatenate((np.array([-1e6]),np.percentile(pred_surv, np.arange(100/n_bins,100,100/n_bins)),np.array([1e6])))
	bin = pd.cut(pred_surv,cuts,labels=False)
	kmf = KaplanMeierFitter()
	est = []
	ci_upper = []
	ci_lower = []
	mean_pred_surv = []
	for which_bin in range(max(bin)+1):
		kmf.fit(time[bin==which_bin], event_observed=dead[bin==which_bin])
		est.append(np.interp(fu_time, kmf.survival_function_.index.values, kmf.survival_function_.KM_estimate))
		ci_upper.append(np.interp(fu_time, kmf.survival_function_.index.values, kmf.confidence_interval_.loc[:,'KM_estimate_upper_0.95']))
		ci_lower.append(np.interp(fu_time, kmf.survival_function_.index.values, kmf.confidence_interval_.loc[:,'KM_estimate_lower_0.95']))
		mean_pred_surv.append(np.mean(pred_surv[bin==which_bin]))
	est = np.array(est)
	ci_upper = np.array(ci_upper)
	ci_lower = np.array(ci_lower)
	if error_bars:
		plt.errorbar(mean_pred_surv, est, yerr = np.transpose(np.column_stack((est-ci_lower,ci_upper-est))), fmt='o',c=color,label=label)
	else:
		plt.plot(mean_pred_surv, est, markertype, c=color,label=label, alpha=alpha, markersize=markersize)
	return (mean_pred_surv, est) 
開發者ID:MGensheimer,項目名稱:nnet-survival,代碼行數:24,代碼來源:support_study.py

示例2: plot_km_survf

# 需要導入模塊: import lifelines [as 別名]
# 或者: from lifelines import KaplanMeierFitter [as 別名]
def plot_km_survf(data, t_col="t", e_col="e"):
    """
    Plot KM survival function curves.

    Parameters
    ----------
    data: pandas.DataFrame
        Survival data to plot.
    t_col: str
        Column name in data indicating time.
    e_col: str
        Column name in data indicating events or status.
    """
    from lifelines import KaplanMeierFitter
    from lifelines.plotting import add_at_risk_counts
    fig, ax = plt.subplots(figsize=(6, 4))
    kmfh = KaplanMeierFitter()
    kmfh.fit(data[t_col], event_observed=data[e_col], label="KM Survival Curve")
    kmfh.survival_function_.plot(ax=ax)
    plt.ylim(0, 1.01)
    plt.xlabel("Time")
    plt.ylabel("Probalities")
    plt.legend(loc="best")
    add_at_risk_counts(kmfh, ax=ax)
    plt.show() 
開發者ID:liupei101,項目名稱:TFDeepSurv,代碼行數:27,代碼來源:vision.py

示例3: fit_plot

# 需要導入模塊: import lifelines [as 別名]
# 或者: from lifelines import KaplanMeierFitter [as 別名]
def fit_plot(T1, T2, E1, E2, title, unit_of_time, label1, label2):
    kmf1 = KaplanMeierFitter()
    kmf2 = KaplanMeierFitter()
    ax = kmf1.fit(T1, E1, label=label1, alpha=0.05).plot(show_censors=True)
    ax = kmf2.fit(T2, E2, label=label2, alpha=0.05).plot(ax=ax, show_censors=True)
    ax.set_title(title)
    if unit_of_time:
        plt.xlabel(f'timeline ({unit_of_time})')
    lifelines.plotting.add_at_risk_counts(kmf1, kmf2, ax=ax, labels=None)
    figname = ax.figure.canvas.get_window_title()
    ax.figure.canvas.set_window_title(f'Party {mpc.pid} - {figname}')
    return kmf1, kmf2 
開發者ID:lschoe,項目名稱:mpyc,代碼行數:14,代碼來源:kmsurvival.py

示例4: calibration_time_to_event

# 需要導入模塊: import lifelines [as 別名]
# 或者: from lifelines import KaplanMeierFitter [as 別名]
def calibration_time_to_event(Forecast, T, E, bins=10, eps=1e-3):
    """
    Calculate calibration in the time-to-event setting, with integral transform and KM.
    """
    cdfs = Forecast.cdf(T)
    kmf = KaplanMeierFitter()
    kmf.fit(cdfs, E)
    idxs = np.round(np.linspace(0, len(kmf.survival_function_) - 1, 11))
    preds = np.array(kmf.survival_function_.iloc[idxs].index)
    obs = 1 - np.array(kmf.survival_function_.iloc[idxs].KM_estimate)
    slope, intercept = np.polyfit(preds, obs, deg=1)
    return preds, obs, slope, intercept 
開發者ID:stanfordmlgroup,項目名稱:ngboost,代碼行數:14,代碼來源:evaluation.py

示例5: test_kaplan_meier_vs_lifelines

# 需要導入模塊: import lifelines [as 別名]
# 或者: from lifelines import KaplanMeierFitter [as 別名]
def test_kaplan_meier_vs_lifelines(n, p_cens):
    from lifelines import KaplanMeierFitter
    np.random.seed(0)
    durations = np.random.uniform(0, 100, n)
    events = np.random.binomial(1, 1 - p_cens, n).astype('float')
    km = utils.kaplan_meier(durations, events)
    kmf = KaplanMeierFitter().fit(durations, events).survival_function_['KM_estimate']
    assert km.shape == kmf.shape
    assert (km - kmf).abs().max() < 1e-14
    assert (km.index == kmf.index).all() 
開發者ID:havakv,項目名稱:pycox,代碼行數:12,代碼來源:test_utils.py


注:本文中的lifelines.KaplanMeierFitter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。