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


Python estimation.AalenAdditiveFitter类代码示例

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


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

示例1: test_predict_cumulative_hazard_inputs

 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,代码行数:7,代码来源:test_estimation.py

示例2: test_aaf_panel_dataset_with_no_censorship

 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,代码行数:7,代码来源:test_estimation.py

示例3: test_aalen_additive_fit_with_censor

    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,代码行数:26,代码来源:test_estimation.py

示例4: test_using_a_custom_timeline_in_static_fitting

 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,代码行数:8,代码来源:test_estimation.py

示例5: test_large_dimensions_for_recursion_error

 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,代码行数:8,代码来源:test_estimation.py

示例6: test_aaf_panel_dataset

    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,代码行数:8,代码来源:test_estimation.py

示例7: test_aaf_panel_dataset

    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,代码行数:9,代码来源:test_plotting.py

示例8: test_using_a_custom_timeline_in_varying_fitting

 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,代码行数:9,代码来源:test_estimation.py

示例9: test_fit_methods_require_duration_col

    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,代码行数:10,代码来源:test_estimation.py

示例10: test_predict_methods_in_regression_return_same_types

    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,代码行数:11,代码来源:test_estimation.py

示例11: test_prediction_methods_respect_index

    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,代码行数:14,代码来源:test_estimation.py

示例12: test_fit_methods_can_accept_optional_event_col_param

    def test_fit_methods_can_accept_optional_event_col_param(self):
        X = load_regression_dataset()

        aaf = AalenAdditiveFitter()
        aaf.fit(X, 'T', event_col='E')
        assert_series_equal(aaf.event_observed.sort_index(), X['E'].astype(bool), check_names=False)

        aaf.fit(X, 'T')
        npt.assert_array_equal(aaf.event_observed.values, np.ones(X.shape[0]))

        cph = CoxPHFitter()
        cph.fit(X, 'T', event_col='E')
        assert_series_equal(cph.event_observed.sort_index(), X['E'].astype(bool), check_names=False)

        cph.fit(X, 'T')
        npt.assert_array_equal(cph.event_observed.values, np.ones(X.shape[0]))
开发者ID:nerdless,项目名称:lifelines,代码行数:16,代码来源:test_estimation.py

示例13: test_aalen_additive_median_predictions_split_data

    def test_aalen_additive_median_predictions_split_data(self):
        # This tests to make sure that my median predictions statisfy
        # the prediction are greater than the actual 1/2 the time.
        # generate some hazard rates and a survival data set
        n = 2500
        d = 5
        timeline = np.linspace(0, 70, 5000)
        hz, coef, X = generate_hazard_rates(n, d, timeline)
        T = generate_random_lifetimes(hz, timeline)
        X['T'] = T
        # fit it to Aalen's model
        aaf = AalenAdditiveFitter()
        aaf.fit(X, 'T')

        # predictions
        T_pred = aaf.predict_median(X[list(range(6))])
        assert abs((T_pred.values > T).mean() - 0.5) < 0.05
开发者ID:nerdless,项目名称:lifelines,代码行数:17,代码来源:test_estimation.py

示例14: test_nn_cumulative_hazard_will_set_cum_hazards_to_0

    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,代码行数:10,代码来源:test_estimation.py

示例15: test_aalen_additive_smoothed_plot

    def test_aalen_additive_smoothed_plot(self, block):
        # this is a visual test of the fitting the cumulative
        # hazards.
        n = 2500
        d = 3
        timeline = np.linspace(0, 150, 5000)
        hz, coef, X = generate_hazard_rates(n, d, timeline)
        T = generate_random_lifetimes(hz, timeline) + 0.1 * np.random.uniform(size=(n, 1))
        C = np.random.binomial(1, 0.8, size=n)
        X['T'] = T
        X['E'] = C

        # fit the aaf, no intercept as it is already built into X, X[2] is ones
        aaf = AalenAdditiveFitter(coef_penalizer=0.1, fit_intercept=False)
        aaf.fit(X, 'T', 'E')
        ax = aaf.smoothed_hazards_(1).iloc[0:aaf.cumulative_hazards_.shape[0] - 500].plot()
        ax.set_xlabel("time")
        ax.set_title('test_aalen_additive_smoothed_plot')
        self.plt.show(block=block)
        return
开发者ID:,项目名称:,代码行数:20,代码来源:


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