A growing collection of small, self-contained machine learning experiments. Each mini-project lives in its own file (or folder) and can be run on its own.
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtSome projects pull data from Kaggle via kagglehub. Authenticate once if prompted when you first run them.
| Project | File | Topics |
|---|---|---|
| Mall Customer Segmentation | mall_customer_segmentation.py |
K-Means, elbow method, feature scaling |
| Iris KNN | iris_knn.py |
KNN, train/test split, StandardScaler |
| Iris Pipeline + CV | iris_pipeline.py |
Pipeline, cross-validation, KNN |
| Log Loss | log_loss.py |
log loss, accuracy, probability |
| California Housing: Linear vs Dummy | linear_reg_v_dum_baseline.py |
LinearRegression, DummyRegressor, R² |
| California Housing Decision Tree | caliornia_decision_tree.py |
DecisionTree, depth sweep, cross-validation |
| NYC Taxi Fare | nyc_taxi_fare_prediction.py |
pipelines, trees, forests, gradient boosting |
| Credit Card Fraud | credit_fraud_fraud.py |
logistic regression, class weight, threshold cost |
| SVM vs Logistic Regression | svm_vslogistic_regression.py |
SVM, logistic regression, GridSearchCV, recall |
Clusters mall shoppers by annual income and spending score using K-Means.
What it does
- Loads the Mall Customers dataset
- Standardizes the two features
- Plots an elbow curve to help choose
k - Fits K-Means (
k=5by default), plots segments + centroids - Labels each cluster with low / average / high income and spending bands
Run
python mall_customer_segmentation.pyClassifies Iris flowers with K-Nearest Neighbors, comparing odd values of k.
What it does
- Loads the built-in Iris dataset
- Stratified train/test split
- Standardizes features (fit on train, transform test)
- Trains KNN for
k = 1, 3, 5, 7, 9and prints test accuracy
Run
python iris_knn.pySame Iris + KNN setup, but scaling and the classifier are wrapped in a Pipeline, evaluated with 5-fold cross-validation.
What it does
- Loads the Iris dataset
- Builds a
Pipeline(StandardScaler → KNeighborsClassifier)for each oddk - Runs
cross_val_score(..., cv=5)so the scaler is fit only on each fold’s training data - Prints mean and standard deviation of the five fold scores
Run
python iris_pipeline.pyWorks through log loss by hand, then checks the result against scikit-learn.
What it does
- Computes
-log(p)for a few probabilities placed on the true class - Scores two models when the true label is “no” (
p(yes)of 0.6 and 0.99) - Averages those losses and compares them to
sklearn.metrics.log_loss - Thresholds those probabilities at 0.5 and prints accuracy (both put more than half their probability on “yes”, so accuracy is 0)
Run
python log_loss.pyPredicts California median house value and checks whether linear regression beats predicting the training mean.
What it does
- Loads
fetch_california_housing(target is in units of $100,000) - Holds out 20% as a test set
- Fits a
DummyRegressor(mean) and a scaledLinearRegression - Prints test MAE and RMSE in dollars, plus R²
- Prints train vs test R² for the linear model (gap hints at over/underfitting)
Run
python linear_reg_v_dum_baseline.pySame housing data, with a decision-tree depth sweep before a test-set comparison.
What it does
- Loads California housing and holds out 20% as a test set
- Sweeps
max_depthin{1, 2, 3, 5, 8, 12, 20, None}on the training set - Records train R² and 5-fold CV R² (mean ± std) and plots both curves
- Picks the depth with the best CV mean, preferring a shallower tree when it is within one standard deviation
- Compares that tree to a mean dummy and a scaled linear regression on the test set (MAE, RMSE in dollars, R²)
Run
python caliornia_decision_tree.pyPredicts yellow-taxi fare from trip features known at pickup, and compares several regressors on cross-validated MAE.
Shared metric helpers live in ml_utils.py (regression_metrics, format_results).
What it does
- Loads seaborn’s
taxisdataset - Drops
tip,tolls, andtotal(known only after the ride), builds pickup hour and day-of-week, and drops rows missing a borough - Uses distance, passengers, pickup time, and pickup/dropoff borough
- Sweeps decision-tree depth by 5-fold CV MAE and keeps the simpler tree when it is within one standard deviation of the best
- Compares a mean dummy, scaled linear regression, the chosen tree, a random forest, and histogram gradient boosting
- Fits every model once on the full training set, prints test MAE / RMSE / R², and lists the 10 largest absolute errors for linear regression and gradient boosting
Run
python nyc_taxi_fare_prediction.pyTrains logistic regression on the credit card fraud dataset and picks a decision threshold by cost, not by the default 0.5 cutoff.
False positives cost £5 and false negatives cost £500.
What it does
- Loads
creditcard.csvfrom Kaggle (V1–V28,Amount,Time→Class) - Stratified split into train / validation / test (about 60% / 20% / 20%)
- Fits two scaled logistic regressions: a plain baseline and one with
class_weight="balanced" - On validation, prints the confusion matrix, precision and recall at 0.5, ROC-AUC, and average precision
- Sweeps thresholds from 0.01 to 0.99 and keeps the one with the lowest validation cost
- Scores only the cheaper model once on the test set (cost, precision, recall)
Run
python credit_fraud_fraud.pyCompares scaled logistic regression and an RBF support vector classifier on the Wisconsin breast cancer dataset, tuning both for malignant recall.
What it does
- Loads
load_breast_cancerand flips the labels so malignant is the positive class (1) - Prints the benign and malignant counts, then makes a stratified 80/20 train/test split
- Tunes logistic regression over
Cin{0.01, 0.1, 1, 10}with 5-fold stratifiedGridSearchCV, scoring malignant recall - Tunes an RBF
SVCoverCin{0.1, 1, 10, 100}andgammain{scale, 0.001, 0.01, 0.1}the same way - For each model, prints the best parameters, cross-validated recall (mean ± std), and a single test-set confusion matrix, precision, and recall
Run
python svm_vslogistic_regression.pyPersonal repo — use and adapt freely.