This project is a complete Machine Learning system that implements:
- Decision Tree (ID3) from scratch
- Simple Linear Regression from scratch
- Multiple Linear Regression (bonus using sklearn)
It follows a modular pipeline-based architecture similar to industry-level ML systems.
- Built from scratch (no sklearn)
- Entropy & Information Gain
- Recursive tree construction
- Prediction system
- JSON tree export
- Implemented from scratch
- Uses mathematical formula for slope & intercept
- Model evaluation (MSE, R²)
- Uses sklearn
- Supports multiple features
- Separate pipeline
- Modular pipeline design
- Logging across all modules
- Model saving/loading (pickle)
- CLI-based menu system
- Visualization support
decisiontree_and_linearregression/
│
├── decision_tree/
│ ├── src/
│ │ ├── data_ingestion.py
│ │ ├── data_preprocessing.py
│ │ ├── data_split.py
│ │ ├── entropy.py
│ │ ├── information_gain.py
│ │ ├── feature_selection.py
│ │ ├── recursive_id3.py
│ │ ├── prediction.py
│ │ ├── pipeline.py
│ │ ├── train_app.py
│ │ ├── predict_app.py
│ │ ├── model_save.py
│ │ └── visualize_tree.py
│
├── linear_regression/
│ ├── src/
│ │ ├── data_ingestion.py
│ │ ├── data_preprocessing.py
│ │ ├── data_split.py
│ │ ├── model.py
│ │ ├── model_evaluation.py
│ │ ├── pipeline.py
│ │ ├── prediction.py
│ │ └── visualize.py
│ │
│ └── bonus_part/
│ ├── multifeature_preprocessing.py
│ ├── multifeature_model.py
│ └── multifeature_pipeline.py
│
├── main_controller.py
├── main.py
├── logs/
├── outputs/
└── artifacts/
- Load dataset from Kaggle
- Preprocess data (feature selection + encoding)
- Split into train/test
- Build tree using ID3 algorithm
- Evaluate model (accuracy, precision, recall, F1)
- Save model
- Export tree as JSON
- Load dataset
- Select features
- Split data
- Train model using mathematical formula
- Evaluate (MSE, R²)
- Save model
- Visualize regression line
pip install -r requirements.txtpython main.py1. Decision Tree
2. Linear Regression
3. Visualize Linear Regression
4. Multi Feature Linear Regression
5. Exit
-
Choose model
-
Select mode:
- Train
- Predict
[
{"odor": 6, "gill-size": 1, "cap-surface": 2},
{"odor": 3, "gill-size": 0, "cap-surface": 2}
][50, 100, 150]- Model files →
artifacts/ - Logs →
logs/ - Decision Tree JSON →
outputs/decision_tree.json - Regression plot →
outputs/regression_plot.png
- Python
- NumPy
- Pandas
- Scikit-learn (for bonus part)
- Matplotlib
- KaggleHub
Nouman Hafeez
- Passionate about Machine Learning & System Design
- Focused on building production-level ML systems
This project demonstrates:
- Strong ML fundamentals
- Clean architecture
- Pipeline-based thinking