C4W2 Lab2 4.2.5 Issue with Binning loyalty_program_years Using Custom Edges in KBinsDiscretizer

Hello Team,

I’m working on the exercise to create bins based on customer antiquity using KBinsDiscretizer. The goal is to group customers according to predefined ranges: 0-1 years, 1-3 years, 3-5 years, and 5+ years. However, when using KBinsDiscretizer, I noticed that there doesn’t seem to be a direct way to specify custom bin edges like [0, 1, 3, 5, float('inf')].

I can set the number of bins using n_bins, but it looks like the bin edges are generated automatically based on the strategy parameter (here uniform), which actually reslults in bins of equal width, instead of customerised edges.

Should we use an alternative method like pd.cut() instead?

Thanks in advance for your help and insights!