KeyError:“只有系列名称可用作系列数据类型映射中的键。”使用 CoxPHFitter 时

问题描述 投票:0回答:1

当我尝试拟合 Coxph 模型时收到以下错误


   5797                 if col_name in dtype:
   5798                     results.append(
-> 5799                         col.astype(dtype=dtype[col_name], copy=copy, errors=errors)
   5800                     )
   5801                 else:

/opt/python/3.8.0/lib/python3.8/site-packages/pandas/core/generic.py in astype(self, dtype, copy, errors)
   5780             if self.ndim == 1:  # i.e. Series
   5781                 if len(dtype) > 1 or self.name not in dtype:
-> 5782                     raise KeyError(
   5783                         "Only the Series name can be used for "
   5784                         "the key in Series dtype mappings."

KeyError: 'Only the Series name can be used for the key in Series dtype mappings.'

我已经检查了作为解决方案之一中的问题给出的列名称。但它们都不起作用。

以下是我的coxph模型代码:

from lifelines import CoxPHFitter

cph = CoxPHFitter()
results_fin = cph.fit(df, duration_col='Months', event_col='Event')
results_fin.print_summary() 

“事件”和“月份”列都是数字。 请帮助修复错误。

python pandas survival-analysis cox-regression cox
1个回答
0
投票

我也遇到了同样的问题,找不到合适的解决方案。我认为这个功能有一些bug,会向网站报告

© www.soinside.com 2019 - 2024. All rights reserved.