当前位置: 首页>>代码示例>>Python>>正文


Python CoxPHFitter.fit方法代码示例

本文整理汇总了Python中lifelines.estimation.CoxPHFitter.fit方法的典型用法代码示例。如果您正苦于以下问题:Python CoxPHFitter.fit方法的具体用法?Python CoxPHFitter.fit怎么用?Python CoxPHFitter.fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lifelines.estimation.CoxPHFitter的用法示例。


在下文中一共展示了CoxPHFitter.fit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_predict_log_hazard_relative_to_mean_with_normalization

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
    def test_predict_log_hazard_relative_to_mean_with_normalization(self, rossi):
        cox = CoxPHFitter(normalize=True)
        cox.fit(rossi, 'week', 'arrest')

        # they are equal because the data is normalized, so the mean of the covarites is all 0,
        # thus exp(beta * 0) == 1, so exp(beta * X)/exp(beta * 0) = exp(beta * X)
        assert_frame_equal(cox.predict_log_hazard_relative_to_mean(rossi), np.log(cox.predict_partial_hazard(rossi)))
开发者ID:DGaffney,项目名称:lifelines,代码行数:9,代码来源:test_estimation.py

示例2: test_predict_log_hazard_relative_to_mean_without_normalization

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
 def test_predict_log_hazard_relative_to_mean_without_normalization(self, rossi):
     cox = CoxPHFitter(normalize=False)
     cox.fit(rossi, 'week', 'arrest')
     log_relative_hazards = cox.predict_log_hazard_relative_to_mean(rossi)
     means = rossi.mean(0).to_frame().T
     assert cox.predict_partial_hazard(means).values[0][0] != 1.0  
     assert_frame_equal(log_relative_hazards, np.log(cox.predict_partial_hazard(rossi) / cox.predict_partial_hazard(means).squeeze()))
开发者ID:DGaffney,项目名称:lifelines,代码行数:9,代码来源:test_estimation.py

示例3: test_coxph_plotting_normalized

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
 def test_coxph_plotting_normalized(self, block):
     df = load_regression_dataset()
     cp = CoxPHFitter()
     cp.fit(df, "T", "E")
     cp.plot(True)
     self.plt.title('test_coxph_plotting')
     self.plt.show(block=block)
开发者ID:springcoil,项目名称:lifelines,代码行数:9,代码来源:test_plotting.py

示例4: test_print_summary

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
    def test_print_summary(self, rossi):

        import sys
        saved_stdout = sys.stdout
        try:
            out = StringIO()
            sys.stdout = out

            cp = CoxPHFitter()
            cp.fit(rossi, duration_col='week', event_col='arrest')
            cp.print_summary()
            output = out.getvalue().strip().split()
            expected = """n=432, number of events=114

           coef  exp(coef)  se(coef)          z         p  lower 0.95  upper 0.95
fin  -1.897e-01  8.272e-01 9.579e-02 -1.981e+00 4.763e-02  -3.775e-01  -1.938e-03   *
age  -3.500e-01  7.047e-01 1.344e-01 -2.604e+00 9.210e-03  -6.134e-01  -8.651e-02  **
race  1.032e-01  1.109e+00 1.012e-01  1.020e+00 3.078e-01  -9.516e-02   3.015e-01
wexp -7.486e-02  9.279e-01 1.051e-01 -7.124e-01 4.762e-01  -2.809e-01   1.311e-01
mar  -1.421e-01  8.675e-01 1.254e-01 -1.134e+00 2.570e-01  -3.880e-01   1.037e-01
paro -4.134e-02  9.595e-01 9.522e-02 -4.341e-01 6.642e-01  -2.280e-01   1.453e-01
prio  2.639e-01  1.302e+00 8.291e-02  3.182e+00 1.460e-03   1.013e-01   4.264e-01  **
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Concordance = 0.640""".strip().split()
            for i in [0, 1, 2, -2, -1]:
                assert output[i] == expected[i]
        finally:
            sys.stdout = saved_stdout
开发者ID:DGaffney,项目名称:lifelines,代码行数:32,代码来源:test_estimation.py

示例5: test_strata_works_if_only_a_single_element_is_in_the_strata

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
 def test_strata_works_if_only_a_single_element_is_in_the_strata(self):
     df = load_holly_molly_polly()
     del df['Start(days)']
     del df['Stop(days)']
     del df['ID']
     cp = CoxPHFitter()
     cp.fit(df, 'T', 'Status', strata=['Stratum'])
     assert True
开发者ID:nerdless,项目名称:lifelines,代码行数:10,代码来源:test_estimation.py

示例6: test_se_against_Survival_Analysis_by_John_Klein_and_Melvin_Moeschberger

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
    def test_se_against_Survival_Analysis_by_John_Klein_and_Melvin_Moeschberger(self):
        # see table 8.1 in Survival Analysis by John P. Klein and Melvin L. Moeschberger, Second Edition
        df = load_larynx()
        cf = CoxPHFitter(normalize=False)
        cf.fit(df, duration_col='time', event_col='death')

        # standard errors
        actual_se = cf._compute_standard_errors().values
        expected_se = np.array([[0.0143,  0.4623,  0.3561,  0.4222]])
        npt.assert_array_almost_equal(actual_se, expected_se, decimal=2)
开发者ID:nerdless,项目名称:lifelines,代码行数:12,代码来源:test_estimation.py

示例7: test_p_value_against_Survival_Analysis_by_John_Klein_and_Melvin_Moeschberger

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
    def test_p_value_against_Survival_Analysis_by_John_Klein_and_Melvin_Moeschberger(self):
        # see table 8.1 in Survival Analysis by John P. Klein and Melvin L. Moeschberger, Second Edition
        df = load_larynx()
        cf = CoxPHFitter()
        cf.fit(df, duration_col='time', event_col='death')

        # p-values
        actual_p = cf._compute_p_values()
        expected_p = np.array([0.1847, 0.7644,  0.0730, 0.00])
        npt.assert_array_almost_equal(actual_p, expected_p, decimal=2)
开发者ID:nerdless,项目名称:lifelines,代码行数:12,代码来源:test_estimation.py

示例8: test_fit_methods_require_duration_col

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
    def test_fit_methods_require_duration_col(self):
        X = load_regression_dataset()

        aaf = AalenAdditiveFitter()
        cph = CoxPHFitter()

        with pytest.raises(TypeError):
            aaf.fit(X)
        with pytest.raises(TypeError):
            cph.fit(X)
开发者ID:nerdless,项目名称:lifelines,代码行数:12,代码来源:test_estimation.py

示例9: test_predict_methods_in_regression_return_same_types

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
    def test_predict_methods_in_regression_return_same_types(self):
        X = load_regression_dataset()

        aaf = AalenAdditiveFitter()
        cph = CoxPHFitter()

        aaf.fit(X, duration_col='T', event_col='E')
        cph.fit(X, duration_col='T', event_col='E')

        for fit_method in ['predict_percentile', 'predict_median', 'predict_expectation', 'predict_survival_function', 'predict_cumulative_hazard']:
            assert isinstance(getattr(aaf, fit_method)(X), type(getattr(cph, fit_method)(X)))
开发者ID:DGaffney,项目名称:lifelines,代码行数:13,代码来源:test_estimation.py

示例10: test_penalized_output_against_R

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
 def test_penalized_output_against_R(self, rossi):
     # R code:
     #
     # rossi <- read.csv('.../lifelines/datasets/rossi.csv')
     # mod.allison <- coxph(Surv(week, arrest) ~ ridge(fin, age, race, wexp, mar, paro, prio,
     #                                                 theta=1.0, scale=FALSE), data=rossi)
     # cat(round(mod.allison$coefficients, 4), sep=", ")
     expected = np.array([[-0.3641, -0.0580, 0.2894, -0.1496, -0.3837, -0.0822, 0.0913]])
     cf = CoxPHFitter(normalize=False, penalizer=1.0)
     cf.fit(rossi, duration_col='week', event_col='arrest')
     npt.assert_array_almost_equal(cf.hazards_.values, expected, decimal=3)
开发者ID:DGaffney,项目名称:lifelines,代码行数:13,代码来源:test_estimation.py

示例11: test_coef_output_against_Survival_Analysis_by_John_Klein_and_Melvin_Moeschberger

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
    def test_coef_output_against_Survival_Analysis_by_John_Klein_and_Melvin_Moeschberger(self):
        # see example 8.3 in Survival Analysis by John P. Klein and Melvin L. Moeschberger, Second Edition
        df = load_kidney_transplant(usecols=['time', 'death',
                                             'black_male', 'white_male',
                                             'black_female'])
        cf = CoxPHFitter(normalize=False)
        cf.fit(df, duration_col='time', event_col='death')

        # coefs
        actual_coefs = cf.hazards_.values
        expected_coefs = np.array([[0.1596, 0.2484, 0.6567]])
        npt.assert_array_almost_equal(actual_coefs, expected_coefs, decimal=4)
开发者ID:nerdless,项目名称:lifelines,代码行数:14,代码来源:test_estimation.py

示例12: test_output_against_R

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
 def test_output_against_R(self, rossi):
     # from http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-cox-regression.pdf
     # Link is now broken, but this is the code:
     #
     # rossi <- read.csv('.../lifelines/datasets/rossi.csv')
     # mod.allison <- coxph(Surv(week, arrest) ~ fin + age + race + wexp + mar + paro + prio,
     #     data=rossi)
     # cat(round(mod.allison$coefficients, 4), sep=", ")
     expected = np.array([[-0.3794, -0.0574, 0.3139, -0.1498, -0.4337, -0.0849,  0.0915]])
     cf = CoxPHFitter(normalize=False)
     cf.fit(rossi, duration_col='week', event_col='arrest')
     npt.assert_array_almost_equal(cf.hazards_.values, expected, decimal=3)
开发者ID:DGaffney,项目名称:lifelines,代码行数:14,代码来源:test_estimation.py

示例13: test_strata_against_r_output

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
    def test_strata_against_r_output(self, rossi):
        """
        > r = coxph(formula = Surv(week, arrest) ~ fin + age + strata(race,
            paro, mar, wexp) + prio, data = rossi)
        > r
        > r$loglik
        """

        cp = CoxPHFitter(normalize=False)
        cp.fit(rossi, 'week', 'arrest', strata=['race', 'paro', 'mar', 'wexp'], include_likelihood=True)

        npt.assert_almost_equal(cp.summary['coef'].values, [-0.335, -0.059, 0.100], decimal=3)
        assert abs(cp._log_likelihood - -436.9339) / 436.9339 < 0.01
开发者ID:DGaffney,项目名称:lifelines,代码行数:15,代码来源:test_estimation.py

示例14: test_summary

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
    def test_summary(self, rossi):

        cp = CoxPHFitter()
        cp.fit(rossi, duration_col='week', event_col='arrest')
        summDf = cp.summary
        expectedColumns = ['coef',
                           'exp(coef)',
                           'se(coef)',
                           'z',
                           'p',
                           'lower 0.95',
                           'upper 0.95']
        assert all([col in summDf.columns for col in expectedColumns])
开发者ID:DGaffney,项目名称:lifelines,代码行数:15,代码来源:test_estimation.py

示例15: test_prediction_methods_respect_index

# 需要导入模块: from lifelines.estimation import CoxPHFitter [as 别名]
# 或者: from lifelines.estimation.CoxPHFitter import fit [as 别名]
    def test_prediction_methods_respect_index(self, data_pred2):
        x = data_pred2[['x1', 'x2']].ix[:3].sort_index(ascending=False)
        expected_index = pd.Index(np.array([3, 2, 1, 0]))

        cph = CoxPHFitter()
        cph.fit(data_pred2, duration_col='t', event_col='E')
        npt.assert_array_equal(cph.predict_partial_hazard(x).index, expected_index)
        npt.assert_array_equal(cph.predict_percentile(x).index, expected_index)
        npt.assert_array_equal(cph.predict_expectation(x).index, expected_index)

        aaf = AalenAdditiveFitter()
        aaf.fit(data_pred2, duration_col='t', event_col='E')
        npt.assert_array_equal(aaf.predict_percentile(x).index, expected_index)
        npt.assert_array_equal(aaf.predict_expectation(x).index, expected_index)
开发者ID:DGaffney,项目名称:lifelines,代码行数:16,代码来源:test_estimation.py


注:本文中的lifelines.estimation.CoxPHFitter.fit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。