Build segments from a checkable customer table
Use feature mode for one unique customer per row. Every non-ID column must be a numeric feature, so remove names, notes and labels before fitting. Alternatively, choose transaction mode and map customer ID, date and amount columns to build recency, frequency and monetary totals.
Inspect profiles before naming groups
The model standardizes features and fits K-Means with seed 42, five initializations and up to 60 iterations. Read customer counts and average raw features for every group. The chart shows the first feature against cluster ID; it is a partial view of the fitted feature space, not a complete separation plot.
Keep the observation window consistent
RFM depends on the reference date and input history. Deduplicate orders, use a single currency and handle refunds before importing. Export prepared feature rows with customer IDs and labels for review. The generated code starts from that prepared matrix; JavaScript and scikit-learn can choose different local minima despite equivalent settings.
Work through a practical example
Customer Segmentation from a CSV: An RFM Walkthrough explains the input, assumptions and expected output. Continue with RFM Scoring vs K-Means: Which Customer Groups Can You Explain? to compare methods and interpret results.