question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Weird error with Cox PH - Numpy arrays

See original GitHub issue
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/ops.py in na_op(x, y)
   1175             result = expressions.evaluate(op, str_rep, x, y,
-> 1176                                           raise_on_error=True, **eval_kwargs)
   1177         except TypeError:

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/computation/expressions.py in evaluate(op, op_str, a, b, raise_on_error, use_numexpr, **eval_kwargs)
    210         return _evaluate(op, op_str, a, b, raise_on_error=raise_on_error,
--> 211                          **eval_kwargs)
    212     return _evaluate_standard(op, op_str, a, b, raise_on_error=raise_on_error)

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/computation/expressions.py in _evaluate_standard(op, op_str, a, b, raise_on_error, **eval_kwargs)
     63     with np.errstate(all='ignore'):
---> 64         return op(a, b)
     65 

TypeError: can't multiply sequence by non-int of type 'float'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/internals.py in eval(self, func, other, raise_on_error, try_cast, mgr)
   1183             with np.errstate(all='ignore'):
-> 1184                 result = get_result(other)
   1185 

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/internals.py in get_result(other)
   1152             else:
-> 1153                 result = func(values, other)
   1154 

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/ops.py in na_op(x, y)
   1201                     with np.errstate(all='ignore'):
-> 1202                         result[mask] = op(xrav, y)
   1203             else:

TypeError: can't multiply sequence by non-int of type 'float'

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-78-12234b38d026> in <module>()
      2                duration_col='observed_duration',
      3                event_col='defaulted',
----> 4                strata='Term')
      5 cf.print_summary()

~/.conda/envs/mypython3/lib/python3.6/site-packages/lifelines/fitters/coxph_fitter.py in fit(self, df, duration_col, event_col, show_progress, initial_beta, include_likelihood, strata)
    299         self._norm_mean = df.mean(0)
    300         self._norm_std = df.std(0)
--> 301         df = normalize(df, self._norm_mean, self._norm_std)
    302 
    303         E = E.astype(bool)

~/.conda/envs/mypython3/lib/python3.6/site-packages/lifelines/utils/__init__.py in normalize(X, mean, std)
    509         mean = X.mean(0)
    510         std = X.std(0)
--> 511     return (X - mean) / std
    512 
    513 

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/ops.py in f(self, other, axis, level, fill_value)
   1234             return self._combine_frame(other, na_op, fill_value, level)
   1235         elif isinstance(other, ABCSeries):
-> 1236             return self._combine_series(other, na_op, fill_value, axis, level)
   1237         else:
   1238             if fill_value is not None:

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/frame.py in _combine_series(self, other, func, fill_value, axis, level)
   3504                                                    fill_value=fill_value)
   3505         return self._combine_series_infer(other, func, level=level,
-> 3506                                           fill_value=fill_value)
   3507 
   3508     def _combine_series_infer(self, other, func, level=None, fill_value=None):

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/frame.py in _combine_series_infer(self, other, func, level, fill_value)
   3508     def _combine_series_infer(self, other, func, level=None, fill_value=None):
   3509         if len(other) == 0:
-> 3510             return self * NA
   3511 
   3512         if len(self) == 0:

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/ops.py in f(self, other, axis, level, fill_value)
   1239                 self = self.fillna(fill_value)
   1240 
-> 1241             return self._combine_const(other, na_op)
   1242 
   1243     f.__name__ = name

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/frame.py in _combine_const(self, other, func, raise_on_error)
   3541     def _combine_const(self, other, func, raise_on_error=True):
   3542         new_data = self._data.eval(func=func, other=other,
-> 3543                                    raise_on_error=raise_on_error)
   3544         return self._constructor(new_data)
   3545 

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/internals.py in eval(self, **kwargs)
   3195 
   3196     def eval(self, **kwargs):
-> 3197         return self.apply('eval', **kwargs)
   3198 
   3199     def quantile(self, **kwargs):

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/internals.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
   3089 
   3090             kwargs['mgr'] = self
-> 3091             applied = getattr(b, f)(**kwargs)
   3092             result_blocks = _extend_blocks(applied, result_blocks)
   3093 

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/internals.py in eval(self, func, other, raise_on_error, try_cast, mgr)
   1189             raise
   1190         except Exception as detail:
-> 1191             result = handle_error()
   1192 
   1193         # technically a broadcast error in numpy can 'work' by returning a

~/.conda/envs/mypython3/lib/python3.6/site-packages/pandas/core/internals.py in handle_error()
   1172                 # The 'detail' variable is defined in outer scope.
   1173                 raise TypeError('Could not operate %s with block values %s' %
-> 1174                                 (repr(other), str(detail)))  # noqa
   1175             else:
   1176                 # return the values

TypeError: Could not operate nan with block values can't multiply sequence by non-int of type 'float'

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
peadarcoylezopacommented, Oct 9, 2017

Ahh thanks man. I would have done it after work 😃

0reactions
peadarcoylezopacommented, Oct 9, 2017

I dropped Market in the second regression model. Sorry for the lack of clarity.

Is this worth a PR to add a better exception error?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cox PH on Lifelines shows convergence problem
I'm running a Cox PH model using lifelines package on Python. ... ConvergenceError: Convergence halted due to matrix inversion problems.
Read more >
Cross-validation not converging on Cox PH due to dummies
var()) A very low variance means that the column number_arrears_so_far_12 completely determines whether a subject dies or not. So I tried ...
Read more >
Using Time Dependent Covariates and Time Dependent Coe ...
The issue is that the above code does not actually create a time dependent covariate, rather it creates a time-static value for each...
Read more >
Cox Regression - Science topic - ResearchGate
I'm trying to build up a survival curve using Cox PH Regression. However, there are no categorical independent variables (no groups to compare...
Read more >
Survival Analysis in Python (KM Estimate, Cox-PH and AFT ...
First, we need to install and load the following libraries to start with the survival analysis. Numpy: array manipulation; Pandas: Data ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found