A complete AI agency at your fingertips - From frontend wizards to Reddit community ninjas, from whimsy injectors to reality checkers. Each agent is a specialized expert with personality, processes, and proven deliverables.
Shell
Score tied RFM histories without crashing or arbitrary tie splits
Rudy Celekli5621b2451119
diff --git a/support/support-analytics-reporter.md b/support/support-analytics-reporter.mdindex 9cd2441f..351688fc 100644--- a/support/support-analytics-reporter.md+++ b/support/support-analytics-reporter.md@@ -115,10 +115,16 @@ def customer_segmentation_analysis(df):'revenue': 'monetary'})- # Create RFM scores- rfm['r_score'] = pd.qcut(rfm['recency'], 5, labels=[5,4,3,2,1])- rfm['f_score'] = pd.qcut(rfm['frequency'].rank(method='first'), 5, labels=[1,2,3,4,5])- rfm['m_score'] = pd.qcut(rfm['monetary'], 5, labels=[1,2,3,4,5])+ # Percentile bands tolerate sparse cohorts and keep identical values together.+ # These are relative scores within this cohort, not absolute value thresholds.+ def score(values, higher_is_better=True):+ percentile = values.rank(method='average', pct=True)+ band = np.ceil(percentile * 5).clip(1, 5).astype(int)+ return band if higher_is_better else 6 - band++ rfm['r_score'] = score(rfm['recency'], higher_is_better=False)+ rfm['f_score'] = score(rfm['frequency'])+ rfm['m_score'] = score(rfm['monetary'])# Customer segmentsrfm['rfm_score'] = rfm['r_score'].astype(str) + rfm['f_score'].astype(str) + rfm['m_score'].astype(str)