Customer Purchase Prediction with Logistic Regression - A Beginner's End-to-End ML Project A developer built an end-to-end logistic regression project that predicts customer purchase decisions from age, salary, experience, and gender, using an eight-row dataset and scikit-learn's train-test split, StandardScaler, and LogisticRegression pipeline. The model achieved 1.0 accuracy on the two-customer test set and predicted a new customer profile (age 36, salary 950, 6 years experience, female) as a buyer. The writeup emphasizes fitting the scaler only on training data and transforming the test and new-customer inputs with the same scaler. When I finished my first machine learning lectures, I wanted a project that used everything I had learned: data loading, preprocessing, train-test split, scaling, training, and evaluation. So I built a small but complete project: predicting whether a customer will purchase a product , based on their age, salary, experience, and gender. The dataset is tiny 8 customers , which makes it perfect for learning — you can follow every number by hand. | Age | Salary | Experience | Gender | Purchase | |---|---|---|---|---| | 25 | 500 | 2 | Male | 0 | | 32 | 800 | 5 | Female | 1 | | 45 | 1200 | 15 | Male | 1 | | 22 | 400 | 1 | Female | 0 | | 38 | 950 | 8 | Male | 1 | | 28 | 600 | 3 | Female | 0 | | 50 | 1500 | 20 | Male | 1 | | 30 | 700 | 4 | Female | 1 | Purchase is the target: 1 means the customer bought, 0 means they didn't. The rest are the features. Models work with numbers, so the Gender column needs encoding: Male = 0, Female = 1. python import pandas as pd from sklearn.model selection import train test split from sklearn.preprocessing import StandardScaler from sklearn.linear model import LogisticRegression from sklearn.metrics import accuracy score data = { 'Age': 25, 32, 45, 22, 38, 28, 50, 30 , 'Salary': 500, 800, 1200, 400, 950, 600, 1500, 700 , 'Experience': 2, 5, 15, 1, 8, 3, 20, 4 , 'Gender': 'Male', 'Female', 'Male', 'Female', 'Male', 'Female', 'Male', 'Female' , 'Purchase': 0, 1, 1, 0, 1, 0, 1, 1 } df = pd.DataFrame data df 'Gender' = df 'Gender' .map {'Male': 0, 'Female': 1} X = df 'Age', 'Salary', 'Experience', 'Gender' y = df 'Purchase' X train, X test, y train, y test = train test split X, y, test size=0.2, random state=42 Train shape: 6, 4 — Test shape: 2, 4 test size=0.2 means 20% of the data goes to testing. random state=42 makes the split reproducible. Age ranges up to 50, Salary up to 1500. Without scaling, the bigger numbers dominate the model. StandardScaler fixes that — and the key rule is: fit only on the training data , then transform both sets. scaler = StandardScaler X train = scaler.fit transform X train X test = scaler.transform X test never fit transform on test data Since the target is yes/no, this is a classification problem, and logistic regression is the natural first model: model = LogisticRegression model.fit X train, y train y pred = model.predict X test print "Actual: ", list y test 0, 1 print "Predicted:", list y pred 0, 1 print "Accuracy: ", accuracy score y test, y pred 1.0 The model predicted both test customers correctly: accuracy 1.0 . Now the fun part — a brand-new customer: age 36, salary 950, 6 years of experience, female. The new data must go through the same scaler transform, not fit : new customer = 36, 950, 6, 1 new customer scaled = scaler.transform new customer prediction = model.predict new customer scaled print "Approved" if prediction 0 == 1 else "Not Approved" Approved Result: Approved Yes — the model predicts this customer will purchase. If you are learning ML, build this project yourself and change one thing at a time: try a different random state , add a feature, or compare logistic regression with a decision tree. That is where the real learning happens.