0

我有以下数据:

gasdfhourly[['Unit','Hourcount','Target']].head()
Out[377]: 
                       Unit  Hourcount  Target
Date       hour                               
2014-01-01 0     748.816493          1     0.0
           1     759.759946          2     0.0
           2     756.737007          3     0.0
           3     761.075262          4     0.0
           4     765.142517          5     0.0

我试图适应 Cox PH 模型:

from lifelines import CoxPHFitter
cph = CoxPHFitter()
cph.fit(gasdfhourly, duration_col='Hourcount', event_col='Target', show_progress=False)
cph.print_summary() 
X=gasdfhourly['Unit']

但是,在尝试导出生存函数时:

cph.predict_survival_function(X)

我收到以下错误:

Traceback (most recent call last):

  File "<ipython-input-378-6bde79cbbb89>", line 1, in <module>
    cph.predict_survival_function(X)

  File "C:\ProgramData\Anaconda3\lib\site-packages\lifelines\fitters\coxph_fitter.py", line 514, in predict_survival_function
    return exp(-self.predict_cumulative_hazard(X, times=times))

  File "C:\ProgramData\Anaconda3\lib\site-packages\lifelines\fitters\coxph_fitter.py", line 495, in predict_cumulative_hazard
    v = self.predict_partial_hazard(X)

  File "C:\ProgramData\Anaconda3\lib\site-packages\lifelines\fitters\coxph_fitter.py", line 437, in predict_partial_hazard
    return exp(self.predict_log_partial_hazard(X))

  File "C:\ProgramData\Anaconda3\lib\site-packages\lifelines\fitters\coxph_fitter.py", line 459, in predict_log_partial_hazard
    return pd.DataFrame(np.dot(X, self.hazards_.T), index=index)

ValueError: shapes (215,) and (1,1) not aligned: 215 (dim 0) != 1 (dim 0)

有人可以指出我的代码中的错误吗?

4

1 回答 1

0

错误是X=gasdfhourly['Unit'],它产生一个系列,而不是一个数据帧。预测函数需要一个 DataFrame。相反,请尝试X=gasdfhourly[['Unit']](注意两个括号)

于 2019-02-10T20:53:13.383 回答