← Journal

Machine Learning Model Comparison: Finding the Best Algorithm

Comprehensive evaluation of five ML algorithms on a customer-churn classification problem — comparing accuracy, precision, recall, and computational efficiency.

I was tasked with building a classification model to predict customer churn. After preparing a dataset with 10,000 samples and 25 features I evaluated five algorithms head-to-head to find the best solution.

Dataset Overview

FeatureTypeMissingUnique
customer_ageNumeric045
subscription_monthsNumeric036
monthly_spendNumeric121,234
support_ticketsNumeric015

Model Performance — Accuracy

5-Fold Cross-Validation Accuracy (%)
94.2 %
Random Forest
96.8 %
XGBoost
92.5 %
Neural Network
89.3 %
SVM
87.1 %
Logistic Regression
XGBoost leads at 96.8 %. Neural Network is competitive with lower variance.

Implementation

from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
from sklearn.svm import SVC
from sklearn.linear_model import LogisticRegression
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import cross_val_score

models = {
    'Random Forest':      RandomForestClassifier(n_estimators=100, random_state=42),
    'XGBoost':            GradientBoostingClassifier(n_estimators=100, random_state=42),
    'Neural Network':     MLPClassifier(hidden_layer_sizes=(50, 25), max_iter=500),
    'SVM':                SVC(kernel='rbf', probability=True),
    'Logistic Regression': LogisticRegression(max_iter=1000),
}

for name, model in models.items():
    scores = cross_val_score(model, X_train, y_train, cv=5, scoring='accuracy')
    print(f"{name}: {scores.mean():.2%}{scores.std() * 2:.2%})")

Detailed Metrics

Precision / Recall / F1 / AUC-ROC
95
Precision
87
Recall
91
F1-Score
96
AUC-ROC
XGBoost metrics — strong precision with slightly lower recall.

Results

XGBoost emerged as the best model with 96.8% accuracy, followed by Random Forest at 94.2%. The model was deployed to production for proactive customer retention campaigns, reducing monthly churn by 18%.