An unsupervised machine learning project that explores credit card usage and groups customers into interpretable behavioural segments.
Developed for the Fondamenti di Machine Learning final project, using the FinTech Solutions S.p.A. business scenario described in the assignment.
The notebook is written in Italian. This README provides an English overview.
Identify patterns in purchases, cash advances, balances and payments to formulate differentiated marketing hypotheses. The analysis describes observed behaviour; it does not estimate individual credit risk or establish future customer preferences.
The credit card customer dataset supplied for the assignment contains 8,950 customers and 18 columns, including the customer identifier CUST_ID.
Features cover purchase amounts and frequencies, cash advances, transaction counts, balances, credit limits, payments and tenure. The notebook downloads the CSV directly from the source.
- Explore and audit: inspect missing values, duplicates, distributions and consistency between related variables.
- Prepare the data: separate 19 records with purchase inconsistencies; exclude
CUST_IDandMINIMUM_PAYMENTSfrom model features; mark eight cash-advance frequencies above 1 as missing under the documented preprocessing assumption. - Impute and transform: use median imputation, apply
log1pto seven monetary features and standardise all 16 model features. - Compare models: evaluate K-Means for K = 2 through 8 using inertia, silhouette, cluster sizes and profile interpretation, with
random_state=42andn_init=20. - Interpret the final model: examine profiles in the original feature scale, heatmaps and a two-component PCA projection.
- Propose and export: document marketing experiments and export assignments, excluded records, quality checks and segment profiles.
The following values are reported in the saved outputs of the notebook currently published in this repository.
| Metric | Result |
|---|---|
| Customers in the source | 8,950 |
| Customers segmented | 8,931 |
| Records excluded and retained separately | 19 |
| Model features | 16 |
| Selected number of clusters | 4 |
| Silhouette score | 0.211117 |
| Inertia | 84,992.940 |
| Variance explained by two PCA components | 52.039% |
| Cluster | Behavioural profile | Customers | Share of segmented customers |
|---|---|---|---|
| 0 | Predominant use of cash advances | 2,806 | 31.419% |
| 1 | Frequent purchases with high total purchase amounts | 2,184 | 24.454% |
| 2 | Frequent purchases, predominantly in instalments | 2,226 | 24.924% |
| 3 | Less frequent purchases, predominantly one-off | 1,715 | 19.203% |
Why four clusters? The notebook prioritises behavioural detail and interpretability for differentiated campaigns. K = 2 achieves the highest silhouette score among the tested solutions; K = 4 is therefore an interpretive trade-off, not the optimum under that metric.
The final silhouette indicates limited separation. PCA is used only for visualisation, after clustering in the full preprocessed feature space; its two-dimensional view represents approximately half of the variance.
The proposed actions include purchase-use experiments for the cash-advance segment, capped loyalty incentives for frequent purchasers, instalment-management communications and follow-up purchase incentives for less frequent purchasers.
These are proposals, not measured campaign outcomes. The notebook recommends randomised campaign and control groups, predefined evaluation metrics and consideration of incentive costs before drawing conclusions about business value.
- The assumed upper bound of 1 for
CASH_ADVANCE_FREQUENCYrequires confirmation from the data provider. Its median imputation is zero, which does not prove that affected customers never used cash advances. - Excluding
MINIMUM_PAYMENTSand 19 records affects the information available to the model. - Correlated variables and extreme transaction counts can influence distances and cluster assignments.
- Stability across samples, random seeds and alternative preprocessing choices has not been assessed.
- Cluster labels are descriptive and arbitrary; the segmentation is not an individual financial-risk assessment.
The repository contains this README and customer_segmentation.ipynb.ipynb. Charts and tables are embedded in the notebook.
Running the export section creates five CSV files in output_segmentazione/:
clienti_segmentati_kmeans.csvclienti_esclusi.csvregistro_qualita_dati.csvprofili_cluster.csvstrategie_marketing.csv
It also creates risultati_segmentazione_kmeans.zip. These are runtime outputs, not files currently included in the repository. The archive contains results and supporting tables, not serialised trained model objects.
Download the notebook and upload it to Google Colab, or open it in a local Jupyter environment. Run the cells in order with Internet access for the source CSV.
For a local environment, install:
pip install pandas numpy matplotlib seaborn scikit-learn jupyterFull-dataset silhouette calculations for several values of K may take a few minutes. Library versions and future source-data updates can affect reproduced results.