代码之家  ›  专栏  ›  技术社区  ›  IndigoChild

Python中的Cox-PH危险函数

  •  0
  • IndigoChild  · 技术社区  · 7 年前

    我有以下数据:

    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
    

    我试着用考克斯博士的模型来适应它:

    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)
    

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

    1 回复  |  直到 7 年前
        1
  •  0
  •   Cam.Davidson.Pilon    6 年前

    错误是 X=gasdfhourly['Unit'] X=gasdfhourly[['Unit']] (注意两个括号)

    推荐文章