从中提取数据摘要考克斯打印摘要()

2024-09-29 23:16:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我想要print_summary输出的前6行。我该怎么做?你知道吗

我有cox.print_summary()的全部摘要。 cox.summary()为列details I提供了数据帧格式,但是索引摘要并没有提供数据集审查摘要

cph = CoxPHFitter()
cph.fit(self.data_train, duration_col='time', event_col='dead')
cph.print_summary()
'''<lifelines.CoxPHFitter: fitted with 6373 observations, 1974 censored>
      duration col = 'time'
         event col = 'dead'
number of subjects = 6373
  number of events = 4399
    log-likelihood = -34779.52
  time fit was run = 2019-05-09 06:28:06 UTC

---
                    coef  exp(coef)  se(coef)     z      p  -log2(p)  lower 0.95  upper 0.95
dzgroupCHF          0.49       1.64      0.06  8.19 <0.005     51.79        0.37        0.61
dzgroupCirrhosis    0.55       1.73      0.08  6.71 <0.005     35.63        0.39        0.71

等等

results = self.cph.summary
print(results.head())

这将以df格式给出变量的详细信息。但我想:

'''<lifelines.CoxPHFitter: fitted with 6373 observations, 1974 censored>
      duration col = 'time'
         event col = 'dead'
number of subjects = 6373
  number of events = 4399
    log-likelihood = -34779.52
  time fit was run = 2019-05-09 06:28:06 UTC

索引给出错误:

cph.print_summary()[0:9]

TypeError: 'NoneType' object is not subscriptable


Tags: ofeventnumbertime格式colsummaryfit
1条回答
网友
1楼 · 发布于 2024-09-29 23:16:21

其中大多数是模型上可以直接访问的属性。查看代码,打印摘要如下所示:

        print(self)
        print("{} = '{}'".format(justify("duration col"), self.duration_col))

        if self.event_col:
            print("{} = '{}'".format(justify("event col"), self.event_col))
        if self.weights_col:
            print("{} = '{}'".format(justify("weights col"), self.weights_col))

        if self.cluster_col:
            print("{} = '{}'".format(justify("cluster col"), self.cluster_col))

        if self.robust or self.cluster_col:
            print("{} = {}".format(justify("robust variance"), True))

        if self.strata:
            print("{} = {}".format(justify("strata"), self.strata))

        if self.penalizer > 0:
            print("{} = {}".format(justify("penalizer"), self.penalizer))

        print("{} = {}".format(justify("number of subjects"), self._n_examples))
        print("{} = {}".format(justify("number of events"), self.event_observed.sum()))
        print("{} = {:.{prec}f}".format(justify("partial log-likelihood"), self._log_likelihood, prec=decimals))
        print("{} = {}".format(justify("time fit was run"), self._time_fit_was_called))

因此可以使用self._log_likelihoodself._n_examples等访问所需的值

未来的一些工作可能会使提取这些数据变得更容易:https://github.com/CamDavidsonPilon/lifelines/issues/721#issuecomment-497180538

相关问题 更多 >

    热门问题