I built Logistic Regression, Decision Trees, Random Forests, and K-Means from scratch :.. here's what surprised me
说明与用途
作者从零实现了五种机器学习模型,并与 scikit-learn 在 Titanic 数据集上进行比较,发现 KMeans 与 scikit-learn 的惯性完全一致,而其他模型在准确率和召回率上表现不佳。
问题
Implementing common machine learning models from scratch and comparing their performance to scikit-learn on the Titanic dataset.
结果
Custom classifiers lag behind scikit-learn in accuracy and recall, except KMeans which matches scikit-learn inertia exactly.
工作流
- 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
证据
KMeans matched sklearn to the decimal while every classifier trailed.
Same split, same ruler — my models vs scikit-learn:
The pattern: my classifiers systematically under-predict "survived" (recall 0.29–0.44 vs sklearn's 0.71–0.79)
- 记录日期: 2026-10-24T09:11:45.970Z