🤖 AI Fundamentals

Module 2: Machine Learning Deep Dive

📚 Learning Objectives

  • Master three types of machine learning: supervised, unsupervised, reinforcement
  • Understand training data, features, and model parameters
  • Learn how algorithms minimize error and optimize performance
  • Recognize overfitting, underfitting, and generalization
  • Apply machine learning to real-world problems
  • Evaluate model performance using appropriate metrics

🎥 Learning Videos

1. Supervised Learning Explained - Classification & Regression

Mondo FarmsMaize Farming in Zambia: How We Established a Maize Crop at our New Farm
This lesson's video moved.
Find it on YouTube →

2. Unsupervised Learning - Clustering & Pattern Discovery

Mondo FarmsMaize Farming in Zambia: How We Established a Maize Crop at our New Farm
This lesson's video moved.
Find it on YouTube →

3. Reinforcement Learning - Teaching AI Through Rewards

Farm With FredMaize Farming: The Ultimate Guide to Spacing & Preparation
This lesson's video moved.
Find it on YouTube →

4. Training Models: Overfitting, Underfitting & Generalization

THE FARM CHIEFMAIZE SPACING WHEN PLANTING FOR HIGH YIELDS
This lesson's video moved.
Find it on YouTube →

5. Machine Learning Algorithms & How They Learn

CSIR-SARIMaize Land Preparation Techniques
This lesson's video moved.
Find it on YouTube →

📊 Machine Learning Types Comparison

TypeData RequiredHow It WorksReal-World ExampleBest For
Supervised LearningLabeled data (inputs + correct answers)Learn mapping from input → outputSpam filter (ham/spam labeled emails train model)Prediction tasks when you know answer
Unsupervised LearningUnlabeled data (inputs only)Find hidden patterns & groupingsCustomer segmentation (find similar customers)Exploration, pattern discovery
Reinforcement LearningTrial-and-error feedback loopsLearn by receiving rewards/penaltiesGame AI (AlphaGo learns by playing)Decision-making, optimization, control
Semi-SupervisedMix of labeled & unlabeled dataCombine benefits of supervised & unsupervisedDocument classification (some labeled examples)When labeling is expensive/slow

📋 6 Machine Learning Concepts

Concept 1: Features & Feature Engineering

FEATURES are the input variables (data points) your algorithm uses to make predictions. Example: To predict house price, features are: location, square footage, age, number of rooms. More relevant features = better model. Feature engineering = creating new features from existing ones. Example: instead of just "raw income", create "income-to-debt ratio" feature. Good feature selection is 80% of ML success.

Concept 2: Training Data, Validation, & Test Sets

TRAINING SET (60-70%): Used to train model. VALIDATION SET (15-20%): Used to tune hyperparameters and prevent overfitting. TEST SET (15%): Final evaluation on completely unseen data. Never train on test data! This split is critical - if you test on training data, you'll get falsely optimistic results (the model memorized, didn't learn).

Concept 3: Overfitting vs Underfitting

OVERFITTING: Model learns training data TOO well, including noise. Result: excellent on training data, poor on new data. Think: memorizing test answers instead of learning concepts. UNDERFITTING: Model is TOO SIMPLE to capture patterns. Result: poor on both training and new data. Think: memorizing none of it. GOAL: Goldilocks zone - generalize well to new data. Solved by: more data, simpler model, regularization, better features.

Concept 4: Loss Functions & Optimization

LOSS FUNCTION measures how wrong predictions are. Algorithm's goal: minimize loss. During training, algorithm adjusts weights/parameters to reduce error. Example: Predicting house price $500k, actual is $600k, loss = $100k error. Algorithm tweaks itself. Next prediction $580k, loss = $20k (better). Repeat thousands of times. This is called "optimization" or "gradient descent".

Concept 5: Hyperparameters & Model Tuning

HYPERPARAMETERS are settings YOU choose before training (learning rate, tree depth, layer size). Different hyperparameters = different model behavior. Finding best hyperparameters is called "tuning" or "hyperparameter optimization". Common approaches: grid search (try many combinations), random search, Bayesian optimization. This is why ML has "science" and "art" - same algorithm, different settings = different results.

Concept 6: Evaluation Metrics & Model Performance

Different tasks need different metrics. Classification: Accuracy (% correct), Precision (false positive rate), Recall (false negative rate), F1 (balance precision/recall). Regression: MAE (average error), RMSE (penalizes big errors), R² (variance explained). Choose metric matching your problem. Example: Cancer detection - recall matters more than precision (catch all cancers, some false alarms okay). Spam detection - precision matters (false positives annoying).

🎯 Module 2 Quiz

1. What is the main difference between supervised and unsupervised learning?

2. What is overfitting in machine learning?

3. Why do you split data into training, validation, and test sets?

🚀 Real-World Project: Build a Simple ML Model

Part 1: Problem Definition

Choose a prediction problem: predict house price, customer churn, disease diagnosis, crop yield, email spam. Define: What are we predicting? What data do we need? What features matter? Write problem statement.

Part 2: Data Collection & Preparation

Find or create dataset with 100+ examples. Document features (inputs) and target (output). Check data quality: missing values? Outliers? Inconsistencies? Clean data. Split into training (70%), validation (15%), test (15%).

Part 3: Feature Selection

Which features are most important for prediction? Analyze correlations. Remove redundant features. Engineering: create new features if valuable. Document: why did you keep/remove each feature? Rationale matters.

Part 4: Train Multiple Models

Try 3-5 different algorithms: decision tree, random forest, logistic regression, SVM, neural network. Train each on training set. Note: different algorithms, different results. No single best algorithm for all problems.

Part 5: Validation & Hyperparameter Tuning

Evaluate each model on validation set. Try different hyperparameters for top performer. Goal: maximize validation accuracy without overfitting. Document: what hyperparameters worked best? Why?

Part 6: Final Evaluation on Test Set

Run winning model on test set (data it's never seen). Report final accuracy, precision, recall, F1 score as appropriate. This is unbiased performance. Did it generalize well or overfit?

Part 7: Error Analysis & Insights

What mistakes did model make? Are errors random or systematic? When does model fail? Create error budget: if predicting house price, average error was $50k - acceptable? Identify failure patterns.

Part 8: Real-World Deployment Considerations

If deploying this model: What happens when data changes? How often retrain? What safeguards prevent bad predictions? How monitor performance over time? Ethics: any bias issues? Human oversight needed? Document practical deployment plan.

Ready to continue? Move to Module 3: Neural Networks & Deep Learning

→ Next Module