Cox_time_varying_fitter can't be estimated #1412
              
                Unanswered
              
          
                  
                    
                      chenzijin2018
                    
                  
                
                  asked this question in
                Q&A
              
            Replies: 0 comments
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. I am trying to build a cox model. But failed. here attached the log. It looks like some death_only variables has low variance, Then later, there is some non-None axis issue. Can anyone help how should I fix this problem? I know this might be the data issue. I guess I want to ask how can I fix this data issue?
Thank you very much.
ValueError Traceback (most recent call last)
/tmp/ipykernel_196/3504620182.py in
1 final_data=final_data[final_data['dl_size']!=0]
2 cx_md = CoxTimeVaryingFitter()
----> 3 cx_md.fit(final_data, id_col="ID", event_col="Event", start_col="start", stop_col="stop", show_progress=True, formula=f"dl_size + lag_s1 + lag_s2 + lag_s3 + lag_s4 + lag_s5 + lag_s6 + lag_s7 + lag_s8 + lag_s9 + {varlist}")
4
5 parm=cx_md.params_
/opt/oss/conda3/lib/python3.7/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, step_size, robust, strata, initial_point, formula)
204 X = self.regressors.transform_df(df)["beta_"]
205
--> 206 self._check_values(X, events, start, stop)
207
208 self._norm_mean = X.mean(0)
/opt/oss/conda3/lib/python3.7/site-packages/lifelines/fitters/cox_time_varying_fitter.py in _check_values(self, df, events, start, stop)
240 check_nans_or_infs(df)
241 check_low_var(df)
--> 242 check_complete_separation_low_variance(df, events, self.event_col)
243 check_for_numeric_dtypes_or_raise(df)
244 check_for_nonnegative_intervals(start, stop)
/opt/oss/conda3/lib/python3.7/site-packages/lifelines/utils/init.py in check_complete_separation_low_variance(df, events, event_col)
1107
1108 events = events.astype(bool)
-> 1109 deaths_only = df.columns[_low_var(df.loc[events])]
1110 censors_only = df.columns[_low_var(df.loc[~events])]
1111 total = df.columns[_low_var(df)]
/opt/oss/conda3/lib/python3.7/site-packages/pandas/core/indexing.py in getitem(self, key)
929
930 maybe_callable = com.apply_if_callable(key, self.obj)
--> 931 return self._getitem_axis(maybe_callable, axis=axis)
932
933 def _is_scalar_access(self, key: tuple):
/opt/oss/conda3/lib/python3.7/site-packages/pandas/core/indexing.py in _getitem_axis(self, key, axis)
1142 return self._get_slice_axis(key, axis=axis)
1143 elif com.is_bool_indexer(key):
-> 1144 return self._getbool_axis(key, axis=axis)
1145 elif is_list_like_indexer(key):
1146
/opt/oss/conda3/lib/python3.7/site-packages/pandas/core/indexing.py in _getbool_axis(self, key, axis)
946 # caller is responsible for ensuring non-None axis
947 labels = self.obj._get_axis(axis)
--> 948 key = check_bool_indexer(labels, key)
949 inds = key.nonzero()[0]
950 return self.obj._take_with_is_copy(inds, axis=axis)
/opt/oss/conda3/lib/python3.7/site-packages/pandas/core/indexing.py in check_bool_indexer(index, key)
2383 result = key
2384 if isinstance(key, ABCSeries) and not key.index.equals(index):
-> 2385 result = result.reindex(index)
2386 mask = isna(result._values)
2387 if mask.any():
/opt/oss/conda3/lib/python3.7/site-packages/pandas/core/series.py in reindex(self, index, **kwargs)
4578 )
4579 def reindex(self, index=None, **kwargs):
-> 4580 return super().reindex(index=index, **kwargs)
4581
4582 @deprecate_nonkeyword_arguments(version=None, allowed_args=["self", "labels"])
/opt/oss/conda3/lib/python3.7/site-packages/pandas/core/generic.py in reindex(self, *args, **kwargs)
4817 # perform the reindex on the axes
4818 return self._reindex_axes(
-> 4819 axes, level, limit, tolerance, method, fill_value, copy
4820 ).finalize(self, method="reindex")
4821
/opt/oss/conda3/lib/python3.7/site-packages/pandas/core/generic.py in _reindex_axes(self, axes, level, limit, tolerance, method, fill_value, copy)
4841 fill_value=fill_value,
4842 copy=copy,
-> 4843 allow_dups=False,
4844 )
4845
/opt/oss/conda3/lib/python3.7/site-packages/pandas/core/generic.py in _reindex_with_indexers(self, reindexers, fill_value, copy, allow_dups)
4887 fill_value=fill_value,
4888 allow_dups=allow_dups,
-> 4889 copy=copy,
4890 )
4891 # If we've made a copy once, no need to make another one
/opt/oss/conda3/lib/python3.7/site-packages/pandas/core/internals/managers.py in reindex_indexer(self, new_axis, indexer, axis, fill_value, allow_dups, copy, consolidate, only_slice)
668 # some axes don't allow reindexing with dups
669 if not allow_dups:
--> 670 self.axes[axis]._validate_can_reindex(indexer)
671
672 if axis >= self.ndim:
/opt/oss/conda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in _validate_can_reindex(self, indexer)
3783 # trying to reindex on an axis with duplicates
3784 if not self._index_as_unique and len(indexer):
-> 3785 raise ValueError("cannot reindex from a duplicate axis")
3786
3787 def reindex(
ValueError: cannot reindex from a duplicate axis
Beta Was this translation helpful? Give feedback.
All reactions