本文整理汇总了Python中lifelines.estimation.KaplanMeierFitter.fit方法的典型用法代码示例。如果您正苦于以下问题:Python KaplanMeierFitter.fit方法的具体用法?Python KaplanMeierFitter.fit怎么用?Python KaplanMeierFitter.fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lifelines.estimation.KaplanMeierFitter
的用法示例。
在下文中一共展示了KaplanMeierFitter.fit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: score
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def score(T_actual, labels, E_actual):
'''
Return a score based on grouping
'''
scores = []
labels = labels.ravel()
for g in ['high', 'mid', 'low']:
members = labels == g
if np.sum(members) > 0:
kmf = KaplanMeierFitter()
kmf.fit(T_actual[members],
E_actual[members],
label='{}'.format(g))
# Last survival time
if np.sum(E_actual[members]) > 0:
lasttime = np.max(T_actual[members][E_actual[members] == 1])
else:
lasttime = np.nan
# End survival rate, median survival time, member count, last event
subscore = (kmf.survival_function_.iloc[-1, 0],
median_survival_times(kmf.survival_function_),
np.sum(members),
lasttime)
else:
# Rpart might fail in this respect
subscore = (np.nan, np.nan, np.sum(members), np.nan)
scores.append(subscore)
return scores
示例2: test_kmf_with_risk_counts
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_kmf_with_risk_counts(self, block):
data1 = np.random.exponential(10, size=(100))
kmf = KaplanMeierFitter()
kmf.fit(data1)
kmf.plot(at_risk_counts=True)
self.plt.title("test_kmf_with_risk_counts")
self.plt.show(block=block)
示例3: test_passing_in_left_censorship_creates_a_cumulative_density
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_passing_in_left_censorship_creates_a_cumulative_density(self, sample_lifetimes):
T, C = sample_lifetimes
kmf = KaplanMeierFitter()
kmf.fit(T, C, left_censorship=True)
assert hasattr(kmf, 'cumulative_density_')
assert hasattr(kmf, 'plot_cumulative_density_')
assert not hasattr(kmf, 'survival_function_')
示例4: test_stat_error_is_raised_if_too_few_early_deaths
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_stat_error_is_raised_if_too_few_early_deaths(self):
observations = np.array([1, 1, 1, 22, 30, 28, 32, 11, 14, 36, 31, 33, 33, 37, 35, 25, 31,
22, 26, 24, 35, 34, 30, 35, 40, 39, 2])
births = observations - 1
kmf = KaplanMeierFitter()
with pytest.raises(StatError):
kmf.fit(observations, entry=births)
示例5: test_kmf_minimum_observation_bias
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_kmf_minimum_observation_bias():
N = 250
kmf = KaplanMeierFitter()
T, C = exponential_survival_data(N, 0.1, scale=10)
B = 0.01 * T
kmf.fit(T, C, entry=B)
kmf.plot()
plt.title("Should have larger variances in the tails")
示例6: test_show_censor_with_discrete_date
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_show_censor_with_discrete_date(self, block):
T = np.random.binomial(20, 0.1, size=100)
C = np.random.binomial(1, 0.8, size=100)
kmf = KaplanMeierFitter()
kmf.fit(T, C).plot(show_censors=True)
self.plt.title('test_show_censor_with_discrete_date')
self.plt.show(block=block)
return
示例7: test_show_censor_with_index_0
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_show_censor_with_index_0(self, block):
T = np.random.binomial(20, 0.9, size=100) # lifelines should auto put a 0 in.
C = np.random.binomial(1, 0.8, size=100)
kmf = KaplanMeierFitter()
kmf.fit(T, C).plot(show_censors=True)
self.plt.title('test_show_censor_with_index_0')
self.plt.show(block=block)
return
示例8: test_flat_style_no_censor
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_flat_style_no_censor(self, block):
data1 = np.random.exponential(10, size=200)
kmf = KaplanMeierFitter()
kmf.fit(data1, label='test label 1')
ax = kmf.plot(flat=True, censor_styles={'marker': '+', 'mew': 2, 'ms': 7})
self.plt.title('test_flat_style_no_censor')
self.plt.show(block=block)
return
示例9: test_kmf_left_censorship_stats
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_kmf_left_censorship_stats(self):
# from http://www.public.iastate.edu/~pdixon/stat505/Chapter%2011.pdf
T = [3, 5, 5, 5, 6, 6, 10, 12]
C = [1, 0, 0, 1, 1, 1, 0, 1]
kmf = KaplanMeierFitter()
kmf.fit(T, C, left_censorship=True)
actual = kmf.cumulative_density_[kmf._label].values
npt.assert_almost_equal(actual, np.array([0, 0.437500, 0.5833333, 0.875, 0.875, 1]))
示例10: test_negative_times_still_plots
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_negative_times_still_plots(self, block):
n = 40
T = np.linspace(-2, 3, n)
C = np.random.randint(2, size=n)
kmf = KaplanMeierFitter()
kmf.fit(T, C)
ax = kmf.plot()
self.plt.title('test_negative_times_still_plots')
self.plt.show(block=block)
return
示例11: test_kmf_survival_curve_output_against_R
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_kmf_survival_curve_output_against_R(self):
df = load_g3()
ix = df['group'] == 'RIT'
kmf = KaplanMeierFitter()
expected = np.array([[0.909, 0.779]]).T
kmf.fit(df.ix[ix]['time'], df.ix[ix]['event'], timeline=[25, 53])
npt.assert_array_almost_equal(kmf.survival_function_.values, expected, decimal=3)
expected = np.array([[0.833, 0.667, 0.5, 0.333]]).T
kmf.fit(df.ix[~ix]['time'], df.ix[~ix]['event'], timeline=[9, 19, 32, 34])
npt.assert_array_almost_equal(kmf.survival_function_.values, expected, decimal=3)
示例12: test_shifting_durations_doesnt_affect_survival_function_values
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_shifting_durations_doesnt_affect_survival_function_values(self):
T = np.random.exponential(10, size=100)
kmf = KaplanMeierFitter()
expected = kmf.fit(T).survival_function_.values
T_shifted = T + 100
npt.assert_almost_equal(expected, kmf.fit(T_shifted).survival_function_.values)
T_shifted = T - 50
npt.assert_almost_equal(expected[1:], kmf.fit(T_shifted).survival_function_.values)
T_shifted = T - 200
npt.assert_almost_equal(expected[1:], kmf.fit(T_shifted).survival_function_.values)
示例13: test_flat_style_and_marker
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_flat_style_and_marker(self, block):
data1 = np.random.exponential(10, size=200)
data2 = np.random.exponential(2, size=200)
C1 = np.random.binomial(1, 0.9, size=200)
C2 = np.random.binomial(1, 0.95, size=200)
kmf = KaplanMeierFitter()
kmf.fit(data1, C1, label='test label 1')
ax = kmf.plot(flat=True, censor_styles={'marker': '+', 'mew': 2, 'ms': 7})
kmf.fit(data2, C2, label='test label 2')
kmf.plot(ax=ax, censor_styles={'marker': 'o', 'ms': 7}, flat=True)
self.plt.title("testing kmf flat styling + marker")
self.plt.show(block=block)
return
示例14: test_kmf_left_censorship_plots
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_kmf_left_censorship_plots(self, block):
kmf = KaplanMeierFitter()
lcd_dataset = load_lcd()
alluvial_fan = lcd_dataset.loc[lcd_dataset['group'] == 'alluvial_fan']
basin_trough = lcd_dataset.loc[lcd_dataset['group'] == 'basin_trough']
kmf.fit(alluvial_fan['T'], alluvial_fan['C'], left_censorship=True, label='alluvial_fan')
ax = kmf.plot()
kmf.fit(basin_trough['T'], basin_trough['C'], left_censorship=True, label='basin_trough')
ax = kmf.plot(ax=ax)
self.plt.title("test_kmf_left_censorship_plots")
self.plt.show(block=block)
return
示例15: test_kmf_confidence_intervals_output_against_R
# 需要导入模块: from lifelines.estimation import KaplanMeierFitter [as 别名]
# 或者: from lifelines.estimation.KaplanMeierFitter import fit [as 别名]
def test_kmf_confidence_intervals_output_against_R(self):
# this uses conf.type = 'log-log'
df = load_g3()
ix = df['group'] != 'RIT'
kmf = KaplanMeierFitter()
kmf.fit(df.ix[ix]['time'], df.ix[ix]['event'], timeline=[9, 19, 32, 34])
expected_lower_bound = np.array([0.2731, 0.1946, 0.1109, 0.0461])
npt.assert_array_almost_equal(kmf.confidence_interval_['KM_estimate_lower_0.95'].values,
expected_lower_bound, decimal=3)
expected_upper_bound = np.array([0.975, 0.904, 0.804, 0.676])
npt.assert_array_almost_equal(kmf.confidence_interval_['KM_estimate_upper_0.95'].values,
expected_upper_bound, decimal=3)