π 94.89% accuracy on Disease Prediction Β |Β π F1: 0.6485 on E-Commerce (+18% above benchmark) Β |Β π 4 customer segments uncovered in SmartCart Β | 𧬠89% Precision@K on Thyroid Outlier Detection Β |Β π 2 Projects Deployed to Production
Mehran Mushtaq Β· Data Science & Machine Learning Track Β· Python Β· Scikit-Learn
This isnβt just a collection of notebooks.
Itβs a complete learning journey β from implementing algorithms by hand to deploying production-ready ML pipelines β built over the course of an intensive internship.
Every folder tells a chapter of that story: understanding why an algorithm works before trusting a library to do it. Writing clean pipelines. Tuning models properly. Building real projects that solve real problems β and then shipping them.
| Approach | What Was Done |
|---|---|
| From Scratch | Core algorithms implemented in pure Python/NumPy β no sklearn shortcuts |
| Pipelines | Clean, reproducible workflows using sklearn.Pipeline to prevent data leakage |
| GridSearchCV | Systematic hyperparameter tuning on real datasets |
| Cross-Validation | Robust evaluation using k-fold CV with stratification |
| Unsupervised Learning | Clustering, anomaly detection, and dimensionality reduction on real data |
| End-to-End Projects | Full pipelines from raw data β feature engineering β model β evaluation β insight |
| π Deployed | Projects shipped beyond notebooks β live demos accessible online |
These projects have been fully deployed and are accessible as interactive web applications.
| Project | Domain | Live Demo |
|---|---|---|
| π House Price Prediction | Real Estate | |
| π³ CreditWise Loan Approval | Finance |
| Project | Domain | Technique | Key Result | Status |
|---|---|---|---|---|
| π House Price Prediction | Real Estate | Linear Regression + Feature Engineering | Deployed to production | π Live |
| π³ CreditWise Loan Approval | Finance | Classification Pipeline | Deployed to production | π Live |
| π₯ Disease Prediction Pipeline | Healthcare | Voting Classifier Ensemble | 94.89% accuracy | β Complete |
| π E-Commerce Purchase Prediction | Retail | Decision Tree | F1: 0.6485 (+18% benchmark) | β Complete |
| π¬ SmartCart Customer Segmentation | Retail | K-Means + Agglomerative + PCA | 4 actionable customer personas | β Complete |
| 𧬠Thyroid Outlier Detection | Healthcare | Isolation Forest + LOF | 89% Precision@K | β Complete |
ml-scikit-scratch/
β
βββ π Datasets/ # Shared datasets across experiments
β βββ Emotion_classify_Data.csv
β βββ Iris.csv
β βββ Social_Network_Ads.csv
β βββ house_prices_practice.csv
β βββ insurance.csv
β
βββ π linear_regression/
β βββ Linear_regression.ipynb
β βββ README.md
β
βββ π Logistic Regression/
β βββ Logistic_Regressor.ipynb
β βββ README.md
β
βββ π KNN/
β βββ Knn.ipynb
β βββ README.md
β
βββ π Decision tree/
β βββ decision_tree_classifier.ipynb
β βββ decision_tree_regressor.ipynb
β βββ README.md
β
βββ π Naive bayes/
β βββ naive_bayes.ipynb
β βββ README.md
β
βββ π Support Vector Machine/
β βββ svc.ipynb
β βββ svr.ipynb
β βββ README.md
β
βββ π Regularizaton(Lasso:Ridge)/
β βββ lasso_ridge.ipynb
β βββ README.md
β
βββ π ensemble learning/
β βββ bagging/ # Random Forest
β β βββ Random_forest.ipynb
β β βββ README.md
β βββ boosting/ # AdaBoost, Gradient Boosting, XGBoost
β βββ ada_boosting.ipynb
β βββ gradient_boosting.ipynb
β βββ xgboost.ipynb
β βββ README.md
β
βββ π ml-from-scratch/
β βββ linear_reg.ipynb
β βββ logistic_reg.ipynb
β βββ knn_regressor.ipynb
β
βββ π unsupervised ml/
β βββ k_means.ipynb
β βββ hiearchichal_clustering.ipynb
β βββ dbscan.ipynb
β βββ README.md
β
βββ π Projects/
β βββ π house-price-prediction/ # DEPLOYED
β βββ π customer-segmentation-smartcart/
β βββ π CreditWise Loan System/ # DEPLOYED (separate repo)
β βββ π ecommerce-purchase-prediction/
β βββ π thyroid_outlier_detection/
β βββ π disease_prediction_pipeline/
β
βββ notebook_vs_production.md
βββ requirements.txt
βββ README.md
- Linear Regression β Predicting continuous outcomes; from OLS to regularised versions
- Logistic Regression β Binary and multi-class classification with polynomial features
- K-Nearest Neighbours (KNN) β Distance-based classification and regression
- Decision Trees β Classifier & regressor with pre/post pruning strategies
- Naive Bayes β Probabilistic classification with Gaussian distributions
- Support Vector Machines β SVC for classification, SVR for regression
- Regularization β Lasso (L1) and Ridge (L2) to control overfitting
- Bagging β Random Forest with feature importance analysis
- Boosting β AdaBoost, Gradient Boosting, and XGBoost
- K-Means Clustering β Centroid-based segmentation with elbow & silhouette analysis
- Hierarchical Clustering β Agglomerative dendrograms with Ward linkage
- DBSCAN β Density-based, anomaly-resistant clustering
- Linear Regression β Gradient descent, cost function, weight updates
- Logistic Regression β Sigmoid, binary cross-entropy, manual backprop
- KNN Regressor β Euclidean distance, neighbour voting
Domain: Real Estate Β· Type: Supervised Regression Β· Dataset:
house_prices_practice.csvΒ· π Live Demo
The Problem: Predict residential property sale prices from structural and neighbourhood features β a classic, high-value regression problem.
Approach & Key Decisions:
- Exploratory Data Analysis: Identified key drivers of price β GrLivArea, OverallQual, TotalBsmtSF, and neighbourhood β through correlation analysis and visualisations
- Feature Engineering: Created interaction features (e.g. total floor area), handled missing values with domain-aware imputation, and log-transformed the skewed target variable to improve model fit
- Preprocessing Pipeline:
ColumnTransformerapplied scaling to numerical features and one-hot encoding to categorical ones inside a singlesklearn.Pipeline - Model Selection: Evaluated Linear Regression, Ridge, and Lasso β tuned regularisation strength via
GridSearchCV - Deployment: Exported the trained pipeline and built an interactive Streamlit web app so anyone can input house features and receive an instant price estimate
Highlights:
| Aspect | Detail |
|---|---|
| Target | Sale price (log-transformed) |
| Key Features | Living area, overall quality, basement size, year built, neighbourhood |
| Preprocessing | Median imputation, OneHot encoding, StandardScaler |
| Deployment | Streamlit web application |
Tech: pandas, numpy, matplotlib, seaborn, sklearn (Pipeline, Ridge, Lasso, GridSearchCV), streamlit
Domain: Finance Β· Type: Supervised Classification Β· Deliverable: Notebook + Production
.pyscript + Live App Β· π Live Demo Β· π Repository
The Problem: Manual loan approval is slow, inconsistent, and prone to bias. CreditWise needed an automated classification system to assess applicant risk from financial and demographic data β consistently, at scale.
Approach & Key Decisions:
- Feature Engineering: Derived risk signals β debt-to-income proxies, employment stability indicators, and interaction terms between credit history and income band
- Preprocessing Pipeline:
ColumnTransformerapplied different strategies to numerical (imputation + scaling) and categorical (encoding) features simultaneously - Model Selection: Logistic Regression, Random Forest, and Gradient Boosting evaluated; best model tuned with
GridSearchCV - Production Delivery: Final model exported as a standalone
.pyscript and deployed as an interactive Streamlit application β accessible via the live demo link above
Highlights:
| Aspect | Detail |
|---|---|
| Input features | Income, loan amount, credit history, employment, dependents, property area |
| Preprocessing | Median imputation, OneHot encoding, StandardScaler |
| Evaluation | Accuracy, Precision, Recall, F1, Confusion Matrix |
| Deployment | Streamlit web application (separate repo) |
Tech: pandas, sklearn (Pipeline, ColumnTransformer, GridSearchCV, RandomForestClassifier, GradientBoostingClassifier, LogisticRegression), matplotlib, streamlit
Domain: Healthcare Β· Type: Supervised Classification Β· Dataset: 9,800 patients (NovaGen Research Labs)
The Problem: NovaGen Research Labs needed a reliable automated system to classify patients as healthy or at risk based on clinical features β to streamline clinical trial participant selection and reduce manual screening time.
Approach & Key Decisions:
- Pipeline-first design: Entire workflow (imputation β encoding β scaling β model) encapsulated in a single
sklearn.Pipelineβ zero data leakage guaranteed - Ensemble strategy: Hard-voting classifier combining Logistic Regression, Random Forest, and NaΓ―ve Bayes β majority vote reduces the variance of any single model
- Stratified K-Fold CV: Class proportions preserved across every fold β critical for a medical dataset
- Evaluation focus: Optimised for recall alongside accuracy β in clinical settings, false negatives are the higher-risk failure mode
Results:
| Metric | Score |
|---|---|
| Accuracy | 94.89% |
| CV Recall | 95.46% |
| Validation Strategy | Stratified K-Fold Cross-Validation |
| Model | Hard-Voting Ensemble (LR + RF + NB) |
Tech: pandas, sklearn (Pipeline, VotingClassifier, LogisticRegression, RandomForestClassifier, GaussianNB, StratifiedKFold, cross_val_score)
Domain: Retail Β· Type: Supervised Classification Β· Dataset: 12,330 browsing sessions (ShopSmart)
The Problem: Only ~15% of ShopSmartβs 12,330 recorded browsing sessions ended in a purchase. The marketing team needed a model to identify which visitors were likely to convert.
Approach & Key Decisions:
- Class imbalance handling:
class_weight='balanced'in the Decision Tree forces attention on the minority (purchase) class - Depth pruning:
max_depthtuned via GridSearchCV to prevent overfitting on the majority class - Evaluation: Prioritised F1-Score as the primary metric β the harmonic mean of precision and recall
Results:
| Metric | Score |
|---|---|
| F1-Score | 0.6485 |
| Benchmark F1 | 0.55 |
| Improvement | +18% above benchmark |
| Class Imbalance | 85% non-purchase / 15% purchase |
Tech: pandas, sklearn (DecisionTreeClassifier, GridSearchCV, classification_report, train_test_split), matplotlib, seaborn
Domain: Retail Β· Type: Unsupervised Learning Β· Dataset: 2,240 customers Γ 22 features
The Problem: SmartCart was treating all customers the same β one message, one offer, one strategy. The goal was to discover natural groupings so marketing, product, and retention teams could act with precision.
Approach & Key Decisions:
- Feature engineering:
Age,Customer_Tenure_Days,Total_Spending,Total_Childrenderived from raw columns - Outlier removal: Customers aged 90+ and income above $600k dropped
- Dimensionality reduction: PCA reduced the feature space to 4 principal components (~55% variance explained)
- K selection: Elbow Method + Silhouette Score both converged on k = 4
- Final model: Agglomerative Clustering (Ward linkage) selected over K-Means for deterministic, tighter cluster boundaries
Results β Discovered Customer Segments:
| Cluster | Avg Income | Avg Spending | Profile |
|---|---|---|---|
| 0 | ~$42,706 | ~$327 | Budget-conscious, larger families |
| 1 | ~$66,279 | ~$1,055 | Affluent loyalists, catalog-heavy |
| 2 | ~$35,326 | ~$110 | Low-income, high web visits |
| 3 | ~$74,727 | ~$1,271 | Premium spenders, fewest children |
Tech: pandas, numpy, seaborn, matplotlib, sklearn (PCA, KMeans, AgglomerativeClustering, silhouette_score), kneed
Domain: Healthcare Β· Type: Unsupervised Anomaly Detection Β· Dataset: 1,000 patient lab records
The Problem: In 1,000 thyroid hormone lab results, a small number of patients had clinically abnormal profiles β but no labels indicated which ones. The system had to find anomalies without any ground truth.
Approach & Key Decisions:
- Dual-detector approach: Isolation Forest (global anomalies) + LOF (local outliers) β agreement between both increases confidence in flagged cases
- No labels required: System learns the βnormalβ distribution from the data itself
- Validation: Flagged patients cross-checked against clinical reference ranges for hypo/hyperthyroid conditions
Results:
| Metric | Score |
|---|---|
| Precision@K | 89% |
| Detectors Used | Isolation Forest + LOF |
| Labels Required | None (fully unsupervised) |
Tech: pandas, numpy, sklearn (IsolationForest, LocalOutlierFactor, StandardScaler), matplotlib, seaborn
# Clone the repository
git clone https://github.com/mehranmushtaq/ml-scikit-scratch.git
# Navigate into the repo
cd ml-scikit-scratch
# (Recommended) Create a virtual environment
python -m venv venv
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Launch Jupyter
jupyter notebookData Preprocessing & Feature Engineering
Encoding (LabelEncoder, One-Hot, ColumnTransformer)
Train/Test Split with Stratification
StandardScaler inside Pipelines (zero data leakage)
GridSearchCV for Hyperparameter Tuning
Cross-Validation (k-fold, stratified)
Class Imbalance Handling (class_weight, resampling)
Dimensionality Reduction via PCA
Unsupervised Validation (Elbow Method, Silhouette Score)
Anomaly Detection (Isolation Forest, LOF)
Model Evaluation (Accuracy, F1, Precision, Recall, AUC)
Confusion Matrix Analysis
Feature Importance Visualisation
Algorithms Implemented From Scratch (NumPy only)
Model Deployment (Streamlit)
Mehran Mushtaq Β· Data Science & Machine Learning Track
βFirst, solve the problem. Then, write the code.β β John Johnson