LearnCV.ai

Teaching AI visually and practically!


Project maintained by purus15987 Hosted on GitHub Pages — Theme by mattgraham

πŸ§ͺ Practice Lab – 2: NumPy & ML Model Design

🎯 Objective:

Practice building and testing basic machine learning algorithms from scratch using only NumPy (no TensorFlow/PyTorch for model internals). Also practice clean coding with OOP (Object-Oriented Programming).


πŸ’» Lab Problems (Choose one)

Easy Level

  1. Linear Regression – do both:

    • Closed-form solution (normal equation)
    • Gradient Descent (add Ridge regularization)
  2. Data Split & Evaluation – create functions to:

    • Split data into train/validation/test sets
    • Apply scaling
    • Calculate metrics (MSE, MAE, RΒ²)

Medium Level

  1. Logistic Regression (Binary):

    • L2 regularization
    • Stable math using log-sum-exp
    • SGD or mini-batch gradient descent
  2. K-Nearest Neighbours (KNN):

    • Different distance metrics
    • Weighted voting
  3. Small Feed-Forward Neural Network:

    • 1–3 hidden layers
    • Activation functions (ReLU, Sigmoid, Tanh)
    • Batch normalization option

Hard Level

  1. CNN Basics:

    • Implement conv2d and maxpool functions
    • Train a small CNN on part of MNIST
  2. Simple Autoencoder:

    • Reduce dimensions
    • Show reconstruction quality
  3. Optimization Algorithms:

    • Implement and compare: SGD, Momentum, RMSProp, Adam
    • Show and analyze convergence plots

An Engineer’s Trek into Machine Learning

ML-models

source


πŸ› οΈ Lab Instructions

  1. Pick one problem from above.
  2. Plan your code before starting β€” draw a small diagram of your components:

    • Example: DataLoader β†’ Model β†’ Optimizer β†’ Trainer β†’ Metrics
  3. Write Python + NumPy code (vectorized, avoid loops over each sample).
  4. You can use matplotlib for plots, and scikit-learn only for:

    • Loading datasets
    • Checking results (not for internal model work)
  5. Create unit tests to check:

    • Correct shapes
    • Gradients (numeric check)
    • Loss decreases during training
  6. Write a short report (2–4 pages, PDF):

    • Problem statement
    • Design choices
    • Algorithms used
    • Experiments + plots
    • Key results and conclusions
  7. Submit your code + tests + report in a ZIP or GitHub repo.

πŸ“‚ Suggested Project Structure

README.md          # Instructions to run
dataset/           # dataset files (.csv / .png / .xsl)
results/           # experimentation results 
src/               # Code files
  |_model.py
  |_train.py
  |_utils.py
  |_dataloader.py
  |_main.py
  |_eval.py
  |_test.py
tests/             # Unit tests
report.pdf         # Your short write-up

πŸ“Š Example: Linear Regression

Components:

Tests:


πŸ† Marks Distribution (Total 35)

Criteria Marks
Understanding problem 5
Correct, vectorized code 10
Modular design, OOP 7
Experiments & analysis 6
Tests & reproducibility 4
Report clarity 3
Total 35

πŸ™ Credits / Acknowledgements

We acknowledge the use of open-source educational content and inspiration from the following sources:


This lab is intended solely for academic and practice purposes.

Full credit goes to the original authors and maintainers for their contribution to the open-source and data science education community.