Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

22 Commits

Folders and files

Repository files navigation

AI / ML Things

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.

Setup

python -m venv .venv
source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -r requirements.txt

Some projects pull data from Kaggle via kagglehub. Authenticate once if prompted when you first run them.

Mini-projects

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

Mall Customer Segmentation

Clusters mall shoppers by annual income and spending score using K-Means.

What it does

  1. Loads the Mall Customers dataset
  2. Standardizes the two features
  3. Plots an elbow curve to help choose k
  4. Fits K-Means (k=5 by default), plots segments + centroids
  5. Labels each cluster with low / average / high income and spending bands

Run

python mall_customer_segmentation.py

Iris KNN

Classifies Iris flowers with K-Nearest Neighbors, comparing odd values of k.

What it does

  1. Loads the built-in Iris dataset
  2. Stratified train/test split
  3. Standardizes features (fit on train, transform test)
  4. Trains KNN for k = 1, 3, 5, 7, 9 and prints test accuracy

Run

python iris_knn.py

Iris Pipeline + CV

Same Iris + KNN setup, but scaling and the classifier are wrapped in a Pipeline, evaluated with 5-fold cross-validation.

What it does

  1. Loads the Iris dataset
  2. Builds a Pipeline(StandardScaler → KNeighborsClassifier) for each odd k
  3. Runs cross_val_score(..., cv=5) so the scaler is fit only on each fold’s training data
  4. Prints mean and standard deviation of the five fold scores

Run

python iris_pipeline.py

Log Loss

Works through log loss by hand, then checks the result against scikit-learn.

What it does

  1. Computes -log(p) for a few probabilities placed on the true class
  2. Scores two models when the true label is “no” (p(yes) of 0.6 and 0.99)
  3. Averages those losses and compares them to sklearn.metrics.log_loss
  4. 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.py

California Housing: Linear vs Dummy

Predicts California median house value and checks whether linear regression beats predicting the training mean.

What it does

  1. Loads fetch_california_housing (target is in units of $100,000)
  2. Holds out 20% as a test set
  3. Fits a DummyRegressor (mean) and a scaled LinearRegression
  4. Prints test MAE and RMSE in dollars, plus R²
  5. Prints train vs test R² for the linear model (gap hints at over/underfitting)

Run

python linear_reg_v_dum_baseline.py

California Housing Decision Tree

Same housing data, with a decision-tree depth sweep before a test-set comparison.

What it does

  1. Loads California housing and holds out 20% as a test set
  2. Sweeps max_depth in {1, 2, 3, 5, 8, 12, 20, None} on the training set
  3. Records train R² and 5-fold CV R² (mean ± std) and plots both curves
  4. Picks the depth with the best CV mean, preferring a shallower tree when it is within one standard deviation
  5. 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.py

NYC Taxi Fare

Predicts 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

  1. Loads seaborn’s taxis dataset
  2. Drops tip, tolls, and total (known only after the ride), builds pickup hour and day-of-week, and drops rows missing a borough
  3. Uses distance, passengers, pickup time, and pickup/dropoff borough
  4. Sweeps decision-tree depth by 5-fold CV MAE and keeps the simpler tree when it is within one standard deviation of the best
  5. Compares a mean dummy, scaled linear regression, the chosen tree, a random forest, and histogram gradient boosting
  6. 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.py

Credit Card Fraud

Trains 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

  1. Loads creditcard.csv from Kaggle (V1–V28, Amount, Time → Class)
  2. Stratified split into train / validation / test (about 60% / 20% / 20%)
  3. Fits two scaled logistic regressions: a plain baseline and one with class_weight="balanced"
  4. On validation, prints the confusion matrix, precision and recall at 0.5, ROC-AUC, and average precision
  5. Sweeps thresholds from 0.01 to 0.99 and keeps the one with the lowest validation cost
  6. Scores only the cheaper model once on the test set (cost, precision, recall)

Run

python credit_fraud_fraud.py

SVM vs Logistic Regression

Compares scaled logistic regression and an RBF support vector classifier on the Wisconsin breast cancer dataset, tuning both for malignant recall.

What it does

  1. Loads load_breast_cancer and flips the labels so malignant is the positive class (1)
  2. Prints the benign and malignant counts, then makes a stratified 80/20 train/test split
  3. Tunes logistic regression over C in {0.01, 0.1, 1, 10} with 5-fold stratified GridSearchCV, scoring malignant recall
  4. Tunes an RBF SVC over C in {0.1, 1, 10, 100} and gamma in {scale, 0.001, 0.01, 0.1} the same way
  5. 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.py

License

Personal repo — use and adapt freely.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages