我想要print_summary输出的前6行。我该怎么做?
我有cox.print_summary()的全部总结。cox.summary()为列详细信息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”对象不可订阅
发布于 2019-06-02 15:09:38
其中大多数是可以直接访问的模型上的属性。查看代码,print_summary如下所示:
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_likelihood或self._n_examples等来访问所需的值。
有一些未来的工作可以使提取这些数据变得更容易:https://github.com/CamDavidsonPilon/lifelines/issues/721#issuecomment-497180538
https://stackoverflow.com/questions/56053588
复制相似问题