NumPy Text Classifier from Scratch

How it was built

Part 1: Text Preprocessing

Clean raw strings and tokenize them into word lists ready for feature extraction.

Part 2: Vocabulary and Bag-of-Words

Split data, build a fixed vocabulary from training documents only, and convert tokenized text into bag-of-words count vectors.

Part 3: TF-IDF Features

Compute inverse document frequencies from the training BoW matrix and transform count vectors into TF-IDF feature matrices.

Part 4: Logistic Regression Core

Implement sigmoid, probability prediction, binary cross-entropy with L2 penalty, and gradient computation.

Part 5: Training and Threshold Tuning

Train weights with full-batch gradient descent and select the decision threshold that maximizes F1 on a validation set.

Part 6: Evaluation and Predict API

Compute confusion-matrix metrics, expose an end-to-end predict(text) API, and collect false positives vs false negatives for error analysis.