Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

I built Logistic Regression, Decision Trees, Random Forests, and K-Means from scratch :.. here's what surprised me

Description and use

The author implemented five machine learning models from scratch and compared them to scikit-learn on the Titanic dataset, finding that KMeans matches scikit-learn's inertia while other models lag in accuracy and recall.

Problem

Implementing common machine learning models from scratch and comparing their performance to scikit-learn on the Titanic dataset.

Outcome

Custom classifiers lag behind scikit-learn in accuracy and recall, except KMeans which matches scikit-learn inertia exactly.

Workflow

  • 1. Clone mini-sklearn repository
  • 2. Load Titanic dataset (889 rows, 7 features)
  • 3. Split data with test_ratio=0.2, seed=0
  • 4. Train LogisticRegression, DecisionTree, RandomForest, and KMeans from scratch
  • 5. Compute accuracy, precision, recall, F1 for classifiers; inertia for KMeans
  • 6. Compare metrics to scikit-learn equivalents
  • 7. Analyze gaps and identify reasons for underperformance

Evidence

KMeans matched sklearn to the decimal while every classifier trailed.

Source

Same split, same ruler — my models vs scikit-learn:

Source

The pattern: my classifiers systematically under-predict "survived" (recall 0.29–0.44 vs sklearn's 0.71–0.79)

Source

  • Record date: 2026-10-24T09:11:45.970Z