Using sklearn in Colab and received error: Item wrong length 4225 instead of 1409

Viewed 19

I don't understand the error: ValueError: Item wrong length 4225 instead of 1409. Not clear to me what is the wrong length and why.

y_pred = model.predict_proba(x_val)[:,1] # we only want the column that predicts churn

churn_descision = (y_pred >= 0.5)

df_val[churn_descision].customerid


--------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-256-48412e0fc159> in <module>
----> 1 df_val[churn_descision].customerid
      2 #The company could consider sending promotional material to these customers based on the prediction

1 frames
/usr/local/lib/python3.7/dist-packages/pandas/core/frame.py in _getitem_bool_array(self, key)
   3495         elif len(key) != len(self.index):
   3496             raise ValueError(
-> 3497                 f"Item wrong length {len(key)} instead of {len(self.index)}."
   3498             )
   3499 

ValueError: Item wrong length 4225 instead of 1409.
1 Answers

Issue is with the df_val and churn_descision having different shapes. After comparing notes with another student, I see both should be 1409

churn_decision.shape, df_val.shape ((1409,), (1409, 20))

Related