The exponential growth of e-commerce platforms has intensified competition, making precise customer targeting essential for maximizing conversion rates and return on marketing investment. This paper proposes a robust machine learning framework using the K-Nearest Neighbors (KNN) algorithm to predict online shoppers' purchase intentions. Utilizing the UCI Online Shoppers Purchasing Intention Dataset comprising 12,330 sessions and 18 features, we develop a complete end-to-end pipeline encompassing data loading, preprocessing, exploratory data analysis, feature engineering, model development, hyperparameter tuning, and deployment-ready evaluation. Missing values were imputed using column means, and duplicate records were removed, resulting in a refined dataset of 12,205 instances. Numerical features were scaled using MinMaxScaler to optimize distance-based computations inherent to KNN. Hyperparameter tuning via GridSearchCV identified optimal values for the number of neighbors, weighting scheme, and distance metric. The final model employing distance-based weighting achieved a test accuracy of 75.75%. The study demonstrates that KNN, combined with careful preprocessing and threshold tuning, serves as a practical and interpretable solution for precise e-commerce marketing.
Dheeraj Kharvi (Sun,) studied this question.