我正尝试在我的数据集上使用CoxTimeVaryingFitter,但是Baseline_Cumulative_Hazard_中似乎存在类型问题。
我试图减少单个要素以隔离问题,但无法适应下面的数据集。是我的数据有问题,还是模型有问题?谢谢!
代码:
from lifelines import CoxTimeVaryingFitter
import autograd.numpy as np
ctv = CoxTimeVaryingFitter()
comp = 'comp_comp1' #start with comp1
event = 'failure_'+comp.split("_")[1]
cols = ['start', 'stop',
'machineID',
'age',
event,
'volt_24_ma','rotate_24_ma', 'vibration_24_ma', 'pressure_24_ma'
]
ctv.fit(df_X_train[cols].dropna(),
id_col='machineID',
event_col=event,
start_col='start',
stop_col='stop',
show_progress=True,
fit_options={'step_size':0.25})
ctv.print_summary()
ctv.plot()
Data Types
Time-series data
错误:ufunc的循环不支持无可调用exp方法的umpy.flat64类型的参数0
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
AttributeError: 'numpy.float64' object has no attribute 'exp'
The above exception was the direct cause of the following exception:
TypeError Traceback (most recent call last)
<command-1950361299690996> in <module>
23 ]
24
---> 25 ctv.fit(df_X_train[cols].dropna(),
26 id_col='machineID',
27 event_col=event,
/databricks/python/lib/python3.8/site-packages/lifelines/fitters/cox_time_varying_fitter.py in fit(self, df, event_col, start_col, stop_col, weights_col, id_col, show_progress, robust, strata, initial_point, formula, fit_options)
237 self.confidence_intervals_ = self._compute_confidence_intervals()
238 self.baseline_cumulative_hazard_ = self._compute_cumulative_baseline_hazard(df, events, start, stop, weights)
--> 239 self.baseline_survival_ = self._compute_baseline_survival()
240 self.event_observed = events
241 self.start_stop_and_events = pd.DataFrame({"event": events, "start": start, "stop": stop})
/databricks/python/lib/python3.8/site-packages/lifelines/fitters/cox_time_varying_fitter.py in _compute_baseline_survival(self)
815
816 def _compute_baseline_survival(self):
--> 817 survival_df = np.exp(-self.baseline_cumulative_hazard_)
818 survival_df.columns = ["baseline survival"]
819 return survival_df
/databricks/python/lib/python3.8/site-packages/pandas/core/generic.py in __array_ufunc__(self, ufunc, method, *inputs,**kwargs)
1934 self, ufunc: Callable, method: str, *inputs: Any,**kwargs: Any
1935 ):
-> 1936 return arraylike.array_ufunc(self, ufunc, method, *inputs,**kwargs)
1937
1938 # ideally we would define this to avoid the getattr checks, but
/databricks/python/lib/python3.8/site-packages/pandas/core/arraylike.py in array_ufunc(self, ufunc, method, *inputs,**kwargs)
364 # take this path if there are no kwargs
365 mgr = inputs[0]._mgr
--> 366 result = mgr.apply(getattr(ufunc, method))
367 else:
368 # otherwise specific ufunc methods (eg np.<ufunc>.accumulate(..))
/databricks/python/lib/python3.8/site-packages/pandas/core/internals/managers.py in apply(self, f, align_keys, ignore_failures,**kwargs)
423 try:
424 if callable(f):
--> 425 applied = b.apply(f,**kwargs)
426 else:
427 applied = getattr(b, f)(**kwargs)
/databricks/python/lib/python3.8/site-packages/pandas/core/internals/blocks.py in apply(self, func,**kwargs)
376 """
377 with np.errstate(all="ignore"):
--> 378 result = func(self.values,**kwargs)
379
380 return self._split_op_result(result)
TypeError: loop of ufunc does not support argument 0 of type numpy.float64 which has no callable exp method
1条答案
按热度按时间vfh0ocws1#
它似乎正在尝试将
np.exp
应用于具有object
dtype的 Dataframe (或系列或阵列)。在另一个问题中,我有一个简单的Pandas系列:
使用
int
dtype,我可以应用np.exp
并获得浮动dtype系列:但是,如果我将该系列转换为
object
dtype,我会收到错误:如果
a
是一个 Dataframe 而不是一个系列,回溯会更近。