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


Python AalenAdditiveFitter.fit方法代码示例

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


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

示例1: test_aaf_panel_dataset_with_no_censorship

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter import fit [as 别名]
 def test_aaf_panel_dataset_with_no_censorship(self):
     panel_dataset = load_panel_test()
     aaf = AalenAdditiveFitter()
     aaf.fit(panel_dataset, id_col='id', duration_col='t')
     expected = pd.Series([True] * 9, index=range(1, 10))
     expected.index.name = 'id'
     assert_series_equal(aaf.event_observed, expected)
开发者ID:nerdless,项目名称:lifelines,代码行数:9,代码来源:test_estimation.py

示例2: test_aalen_additive_fit_with_censor

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter import fit [as 别名]
    def test_aalen_additive_fit_with_censor(self):
        # this is a visual test of the fitting the cumulative
        # hazards.
        matplotlib = pytest.importorskip("matplotlib")
        from matplotlib import pyplot as plt

        n = 2500
        d = 6
        timeline = np.linspace(0, 70, 10000)
        hz, coef, X = generate_hazard_rates(n, d, timeline)
        X.columns = coef.columns
        cumulative_hazards = pd.DataFrame(cumulative_integral(coef.values, timeline),
                                          index=timeline, columns=coef.columns)
        T = generate_random_lifetimes(hz, timeline)
        X['T'] = T
        X['E'] = np.random.binomial(1, 0.99, n)

        aaf = AalenAdditiveFitter()
        aaf.fit(X, 'T', 'E')

        for i in range(d + 1):
            ax = plt.subplot(d + 1, 1, i + 1)
            col = cumulative_hazards.columns[i]
            ax = cumulative_hazards[col].ix[:15].plot(legend=False, ax=ax)
            ax = aaf.plot(ix=slice(0, 15), ax=ax, columns=[col], legend=False)
        plt.show()
开发者ID:nerdless,项目名称:lifelines,代码行数:28,代码来源:test_estimation.py

示例3: test_predict_cumulative_hazard_inputs

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter import fit [as 别名]
 def test_predict_cumulative_hazard_inputs(self, data_pred1):
     aaf = AalenAdditiveFitter()
     aaf.fit(data_pred1, duration_col='t', event_col='E',)
     x = data_pred1.ix[:5].drop(['t', 'E'], axis=1)
     y_df = aaf.predict_cumulative_hazard(x)
     y_np = aaf.predict_cumulative_hazard(x.values)
     assert_frame_equal(y_df, y_np)
开发者ID:nerdless,项目名称:lifelines,代码行数:9,代码来源:test_estimation.py

示例4: test_using_a_custom_timeline_in_static_fitting

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter import fit [as 别名]
 def test_using_a_custom_timeline_in_static_fitting(self, rossi):
     aaf = AalenAdditiveFitter()
     timeline = np.arange(10)
     aaf.fit(rossi, event_col='arrest', duration_col='week', timeline=timeline)
     npt.assert_array_equal(aaf.hazards_.index.values, timeline)
     npt.assert_array_equal(aaf.cumulative_hazards_.index.values, timeline)
     npt.assert_array_equal(aaf.variance_.index.values, timeline)
     npt.assert_array_equal(aaf.timeline, timeline)
开发者ID:DGaffney,项目名称:lifelines,代码行数:10,代码来源:test_estimation.py

示例5: test_aaf_panel_dataset

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter import fit [as 别名]
    def test_aaf_panel_dataset(self):
        matplotlib = pytest.importorskip("matplotlib")
        from matplotlib import pyplot as plt

        panel_dataset = load_panel_test()
        aaf = AalenAdditiveFitter()
        aaf.fit(panel_dataset, id_col='id', duration_col='t', event_col='E')
        aaf.plot()
开发者ID:nerdless,项目名称:lifelines,代码行数:10,代码来源:test_estimation.py

示例6: test_large_dimensions_for_recursion_error

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter import fit [as 别名]
 def test_large_dimensions_for_recursion_error(self):
     n = 500
     d = 50
     X = pd.DataFrame(np.random.randn(n, d))
     T = np.random.exponential(size=n)
     X['T'] = T
     aaf = AalenAdditiveFitter()
     aaf.fit(X, duration_col='T')
开发者ID:nerdless,项目名称:lifelines,代码行数:10,代码来源:test_estimation.py

示例7: test_aaf_panel_dataset

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

        panel_dataset = load_panel_test()
        aaf = AalenAdditiveFitter()
        aaf.fit(panel_dataset, id_col='id', duration_col='t', event_col='E')
        aaf.plot()
        self.plt.title("test_aaf_panel_dataset")
        self.plt.show(block=block)
        return
开发者ID:springcoil,项目名称:lifelines,代码行数:11,代码来源:test_plotting.py

示例8: test_using_a_custom_timeline_in_varying_fitting

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter import fit [as 别名]
 def test_using_a_custom_timeline_in_varying_fitting(self):
     panel_dataset = load_panel_test()
     aaf = AalenAdditiveFitter()
     timeline = np.arange(10)
     aaf.fit(panel_dataset, id_col='id', duration_col='t', timeline=timeline)
     npt.assert_array_equal(aaf.hazards_.index.values, timeline)
     npt.assert_array_equal(aaf.cumulative_hazards_.index.values, timeline)
     npt.assert_array_equal(aaf.variance_.index.values, timeline)
     npt.assert_array_equal(aaf.timeline, timeline)
开发者ID:nerdless,项目名称:lifelines,代码行数:11,代码来源:test_estimation.py

示例9: test_fit_methods_require_duration_col

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter 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

示例10: test_penalizer_reduces_norm_of_hazards

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter import fit [as 别名]
    def test_penalizer_reduces_norm_of_hazards(self, rossi):
        from numpy.linalg import norm

        aaf_without_penalizer = AalenAdditiveFitter(coef_penalizer=0., smoothing_penalizer=0.)
        assert aaf_without_penalizer.coef_penalizer == aaf_without_penalizer.smoothing_penalizer == 0.0
        aaf_without_penalizer.fit(rossi, event_col='arrest', duration_col='week')

        aaf_with_penalizer = AalenAdditiveFitter(coef_penalizer=10., smoothing_penalizer=10.)
        aaf_with_penalizer.fit(rossi, event_col='arrest', duration_col='week')
        assert norm(aaf_with_penalizer.cumulative_hazards_) <= norm(aaf_without_penalizer.cumulative_hazards_)
开发者ID:DGaffney,项目名称:lifelines,代码行数:12,代码来源:test_estimation.py

示例11: test_nn_cumulative_hazard_will_set_cum_hazards_to_0

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter import fit [as 别名]
    def test_nn_cumulative_hazard_will_set_cum_hazards_to_0(self, rossi):
        aaf = AalenAdditiveFitter(nn_cumulative_hazard=False)
        aaf.fit(rossi, event_col='arrest', duration_col='week')
        cum_hazards = aaf.predict_cumulative_hazard(rossi)
        assert (cum_hazards < 0).stack().mean() > 0

        aaf = AalenAdditiveFitter(nn_cumulative_hazard=True)
        aaf.fit(rossi, event_col='arrest', duration_col='week')
        cum_hazards = aaf.predict_cumulative_hazard(rossi)
        assert (cum_hazards < 0).stack().mean() == 0
开发者ID:DGaffney,项目名称:lifelines,代码行数:12,代码来源:test_estimation.py

示例12: test_input_column_order_is_equal_to_output_hazards_order

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter import fit [as 别名]
    def test_input_column_order_is_equal_to_output_hazards_order(self, rossi):
        aaf = AalenAdditiveFitter()
        expected = ['fin', 'age', 'race', 'wexp', 'mar', 'paro', 'prio']
        aaf.fit(rossi, event_col='arrest', duration_col='week')
        assert list(aaf.cumulative_hazards_.columns.drop('baseline')) == expected

        aaf = AalenAdditiveFitter(fit_intercept=False)
        expected = ['fin', 'age', 'race', 'wexp', 'mar', 'paro', 'prio']
        aaf.fit(rossi, event_col='arrest', duration_col='week')
        assert list(aaf.cumulative_hazards_.columns) == expected
开发者ID:DGaffney,项目名称:lifelines,代码行数:12,代码来源:test_estimation.py

示例13: test_predict_methods_in_regression_return_same_types

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter 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

示例14: test_swapping_order_of_columns_in_a_df_is_okay

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter import fit [as 别名]
    def test_swapping_order_of_columns_in_a_df_is_okay(self, rossi):
        aaf = AalenAdditiveFitter()
        aaf.fit(rossi, event_col='arrest', duration_col='week')

        misorder = ['age', 'race', 'wexp', 'mar', 'paro', 'prio', 'fin']
        natural_order = rossi.columns.drop(['week', 'arrest'])
        deleted_order = rossi.columns - ['week', 'arrest']
        assert_frame_equal(aaf.predict_median(rossi[natural_order]), aaf.predict_median(rossi[misorder]))
        assert_frame_equal(aaf.predict_median(rossi[natural_order]), aaf.predict_median(rossi[deleted_order]))

        aaf = AalenAdditiveFitter(fit_intercept=False)
        aaf.fit(rossi, event_col='arrest', duration_col='week')
        assert_frame_equal(aaf.predict_median(rossi[natural_order]), aaf.predict_median(rossi[misorder]))
        assert_frame_equal(aaf.predict_median(rossi[natural_order]), aaf.predict_median(rossi[deleted_order]))
开发者ID:DGaffney,项目名称:lifelines,代码行数:16,代码来源:test_estimation.py

示例15: test_prediction_methods_respect_index

# 需要导入模块: from lifelines.estimation import AalenAdditiveFitter [as 别名]
# 或者: from lifelines.estimation.AalenAdditiveFitter 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.AalenAdditiveFitter.fit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。