-
-
Save gbushnell/005a3107de8a56c4ab10d920b60184c6 to your computer and use it in GitHub Desktop.
RFM rank customers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#split metric X into quartiles | |
def get_ranks(x): | |
pct_75 = np.percentile(x, 75) | |
pct_50 = np.percentile(x, 50) | |
pct_25 = np.percentile(x, 25) | |
return {'max':x.max(), '75':pct_75, '50':pct_50, '25':pct_25, 'min':x.min()} | |
#rank Recency metric | |
def rank_r(x): | |
i = x.R_days_since_last_invoice | |
r = 0 | |
if i <= R_pct['25']: | |
r = 1 | |
if (i >= R_pct['25']) and (i < R_pct['50']): | |
r = 2 | |
if (i >= R_pct['50']) and (i < R_pct['75']): | |
r = 3 | |
if i >= R_pct['75']: | |
r = 4 | |
return r | |
#.... F and M are ranked similarly, see GitHub for full code. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment