← Back to Projects
Machine LearningClassification

Beverage Sales Cluster Classification with KNN & Random Forest

Machine Learning — Supervised Classification

Project Overview

This project continues the Beverage Sales clustering work by using the generated cluster labels as the classification target. K-Nearest Neighbors and Random Forest are trained to learn the cluster assignment patterns from Customer_Type, Unit_Price, Quantity, Discount, and Total_Price.

Tools Used

PythonPandasNumPySeabornscikit-learnKNNRandom ForestStandardScalerLabelEncoderSimpleImputer

Dataset & Target

The input dataset is hasil_clustering.csv, generated from the previous Beverage Sales K-Means project. After removing rows with missing cluster labels, 206,452 labeled records are used. The feature set contains five variables, while Cluster (0, 1, or 2) becomes the target label.

Machine Learning Workflow

Load Clustered Dataset → Separate Features & Target → Label Encoding → Mean Imputation → Standardization → 80/20 Train-Test Split → Train KNN & Random Forest → Evaluate Classification Performance

Model Evaluation

01

KNN achieved 99.983% accuracy with weighted precision, recall, and F1-score all around 99.983%.

02

Random Forest achieved 99.988% accuracy and slightly outperformed KNN with fewer misclassifications.

03

The test set contains 41,291 samples, while the training set contains 165,161 samples.

04

Hyperparameter tuning was not performed because both baseline models already achieved performance above 99% on the test set.

Interpretation

01

Random Forest is the stronger model in this experiment, although the performance gap from KNN is very small.

02

Because the target labels originate from K-Means clustering built from the same feature space, the classification task primarily learns to reproduce the previously discovered cluster boundaries rather than predict an independent business outcome.

Classification Results

KNN and Random Forest classification performance
Performance comparison between KNN and Random Forest
KNN confusion matrix
KNN confusion matrix based on the notebook test predictions
Random Forest confusion matrix
Random Forest confusion matrix based on the notebook test predictions