thomasjpfan/ml-journal

IndexingError: Too many indexers

YevhenDeriy opened this issue · 1 comments

Hi Thomas,

First of all, thank you for this great analysis. It has been very helpful to me as I learn about survival analysis. Would you be able to tell me the source of the error below? I get it when trying to plot the 'Maximum expected lifetime value'.

Thanks,
Yevhen

IndexingError Traceback (most recent call last)
in
1 #
2 monthly_charges = np.arange(20, 240)
----> 3 lifetime_value = get_expected_value(cph, monthly_charges)
4 lifetime_max_arg = np.argmax(lifetime_value)
5 lifetime_max = np.max(lifetime_value)

in get_expected_value(fitter, monthly_charges)
66 for i, mc in enumerate(monthly_charges):
67 X['MonthlyCharges'] = mc
---> 68 output[i] = mc*fitter.predict_expectation(X).iloc[0,0]
69 return output

C:\Anaconda\lib\site-packages\pandas\core\indexing.py in getitem(self, key)
1759 except (KeyError, IndexError, AttributeError):
1760 pass
-> 1761 return self._getitem_tuple(key)
1762 else:
1763 # we by definition only have the 0th axis

C:\Anaconda\lib\site-packages\pandas\core\indexing.py in _getitem_tuple(self, tup)
2064 def _getitem_tuple(self, tup: Tuple):
2065
-> 2066 self._has_valid_tuple(tup)
2067 try:
2068 return self._getitem_lowerdim(tup)

C:\Anaconda\lib\site-packages\pandas\core\indexing.py in _has_valid_tuple(self, key)
698 for i, k in enumerate(key):
699 if i >= self.ndim:
--> 700 raise IndexingError("Too many indexers")
701 try:
702 self._validate_key(k, i)

IndexingError: Too many indexers

Sorry for the last response. I updated the notebook to be up to be compatible with the latest version of lifetimes. It should work now!