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:
- Problem Definition: Identifying goals and Key Performance Indicators (KPIs).
- Data Collection: Gathering relevant data via APIs, web scraping, or databases.
- Data Preparation: Cleaning and transforming raw data into a suitable format.
- Model Selection: Choosing algorithms based on data characteristics.
- Model Training: The algorithm learns from prepared data.
- Model Evaluation: Assessing effectiveness using performance metrics.
- Model Tuning and Optimization: Fine-tuning hyperparameters (e.g., learning rate).
- Model Deployment: Integrating the model into production (e.g., cloud platforms).
- 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 (NaN), removing duplicates, fixing structural errors, outlier detection (using Z-score or IQR), and normalization.
- Normalization Types:
- Min-Max Normalization: Scaling data between 0 and 1.
- Z-Score Normalization: Centering data around a mean of 0 with a standard deviation of 1.
Machine Learning Algorithms and Model Training
- Supervised Learning: Models trained on labeled data.
- Linear Regression: Predicts continuous values (Y=bx+c).
- Logistic Regression: Predicts binary outcomes (0 or 1).
- 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%), Validation (10%−20%), and Test (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 (R2) 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), Joblib (.joblib), TensorFlow SavedModel, ONNX, and PyTorch TorchScript (.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.