SWDML501: Machine Learning Fundamentals Notes

Module Overview and Machine Learning Life Cycle

  • Module Identity: SWDML501: Machine Learning Fundamentals, RQF LEVEL 5, published October, 2024 by Rwanda TVET Board (RTB) with support from KOICA through the TQUM Project.
  • Machine Learning (ML): A subset of Artificial Intelligence (AI) that enables systems to learn from data and improve without explicit programming.
  • ML Life Cycle: A cyclic process to build efficient projects, consisting of:
    1. Problem Definition: Identifying goals and Key Performance Indicators (KPIs).
    2. Data Collection: Gathering relevant data via APIs, web scraping, or databases.
    3. Data Preparation: Cleaning and transforming raw data into a suitable format.
    4. Model Selection: Choosing algorithms based on data characteristics.
    5. Model Training: The algorithm learns from prepared data.
    6. Model Evaluation: Assessing effectiveness using performance metrics.
    7. Model Tuning and Optimization: Fine-tuning hyperparameters (e.g., learning rate).
    8. Model Deployment: Integrating the model into production (e.g., cloud platforms).
    9. Monitoring and Maintenance: Tracking performance and addressing drift.

Data Pre-processing and Big Data Characteristics

  • The 6 V's of Big Data: Volume (amount), Variety (types), Veracity (trustworthiness), Value (usefulness), Variability (inconsistency), and Velocity (speed of generation).
  • Data Types:
    • Structured: Predictable, predefined schema (e.g., Tabular, Time-Series).
    • Semi-structured: Mix of tag-based and unstructured (e.g., JSON, XML).
    • Unstructured: No predefined format (e.g., images, audio, video, PDF).
  • Data Cleaning Steps: Understanding data, handling missing values (NaNNaN), removing duplicates, fixing structural errors, outlier detection (using Z-score or IQR), and normalization.
  • Normalization Types:
    • Min-Max Normalization: Scaling data between 00 and 11.
    • Z-Score Normalization: Centering data around a mean of 00 with a standard deviation of 11.

Machine Learning Algorithms and Model Training

  • Supervised Learning: Models trained on labeled data.
    • Linear Regression: Predicts continuous values (Y=bx+cY = bx + c).
    • Logistic Regression: Predicts binary outcomes (00 or 11).
    • Decision Trees, Random Forest, Support Vector Machines (SVM), k-Nearest Neighbours (KNN), and Naive Bayes.
  • Unsupervised Learning: Models learn from unlabeled data to find patterns.
    • K-Means Clustering: Partitioning data into groups based on similarity.
    • Principal Component Analysis (PCA): Dimensionality reduction.
    • Hierarchical Clustering: Agglomerative (bottom-up) or Divisive (top-down) approaches.
  • Reinforcement Learning: Agents learn through interaction and feedback (rewards/penalties), using algorithms like Q-Learning and Deep Q-Networks (DQN).
  • Model Training Process:
    • Split ratios: Train (60%−70%60\%-70\%), Validation (10%−20%10\%-20\%), and Test (20%−30%20\%-30\%).
    • Initialization: Assigning initial parameters (weights and biases).
    • Fitting: Adjusting parameters to minimize error.

Model Evaluation and Hyperparameter Tuning

  • Regression Metrics: Root Mean Squared Error (RMSE), Mean Squared Error (MSE), and R-squared (R2R^2) to measure variance explanation.
  • Hyperparameter Search Space: The range of values explored (e.g., alpha in Ridge/Lasso).
    • Grid Search: Systematic exploration of all specified combinations.
    • Random Search: Sampling combinations from a distribution.
  • Bias and Variance:
    • Bias (Underfitting): Model is too simple to capture patterns.
    • Overfitting: Model learns noise rather than underlying patterns.

Model Deployment and Integration

  • Deployment Definition: Integrating a trained model into production to return outputs based on inputs.
  • Serving Methods:
    • Real-time Serving: Low latency for immediate response.
    • Batch Serving: Processing large volumes periodically.
  • Model Formats: Pickle (.pkl.pkl), Joblib (.joblib.joblib), TensorFlow SavedModel, ONNX, and PyTorch TorchScript (.pt.pt).
  • Tools: Flask (web framework for RESTful APIs), Gradio (interface builder), Postman (API testing), and tools like Prometheus/Grafana for monitoring.
  • Loading Strategies: Eager Loading, Lazy Loading, On-Demand Loading, and Caching.

Questions & Discussion

  • Theoretical Activity 1.1.1: Topics include defining Machine Learning, explaining the ML life cycle, and differentiating AI, ML, and Deep Learning.
  • Practical Activity 1.3.2: Task involves gathering datasets like the iris dataset manually or using Pandas and Scikit-learn.
  • Practical Activity 1.5.2: Instructions for performing data cleaning for inconsistencies on a car dataset, including handling mileage units and encoding categorical features.
  • Theoretical Assessment LO2: Questions cover algorithm purposes (e.g., PCA for dimensionality reduction, Isolation Forest for anomaly detection).
  • Practical Assessment LO3: Students are tasked to deploy a hospital readmission prediction model using Scikit-Learn, TensorFlow, or PyTorch, including designing an API and formatting well-structured responses.