Machine Learning Fundamentals
AI Basics·beginner·~25 min read
- machine-learning
- ai
- supervised
- unsupervised
- reinforcement
- generative-ai
- aws
What you'll learn
1. What is Machine Learning?
Machine learning is a subset of artificial intelligence that gives systems the ability to learn and improve from data without being explicitly programmed for every scenario. ---
2. Types of Machine Learning
Supervised Learning
Every training example has a corresponding label. The model learns a mapping from inputs → outputs. | Task Type | Output | Examples | |-----------|--------|----------| | Classification | Discrete category | Spam detection, image recognit…
Unsupervised Learning
No labels for training data. The model finds hidden patterns or structure in the data. | Task Type | What It Finds | Examples | |-----------|--------------|----------| | Clustering | Groups of similar data points | Customer segmentation,…
Reinforcement Learning
The model learns through consequences of actions in a specific environment. It receives rewards for good actions and penalties for bad ones. | Component | Role | |-----------|------| | Agent | Makes decisions (the learner) | | Environmen…
3. The ML Workflow
---
4. Key ML Concepts
Bias-Variance Trade-off
| Concept | Meaning | Symptom | |---------|---------|---------| | High Bias | Model is too simple (underfitting) | Low training accuracy, low test accuracy | | High Variance | Model is too complex (overfitting) | High training accuracy,…
Train/Test/Validation Split
Cross-validation (k-fold): Split data into k folds, train on k-1, validate on 1. Rotate k times. Averages out variance in evaluation.
Evaluation Metrics
| Metric | Formula | Use When | |--------|---------|----------| | Accuracy | Correct / Total | Balanced classes | | Precision | TP / (TP + FP) | Cost of false positive is high (spam filter) | | Recall | TP / (TP + FN) | Cost of missing p…
Feature Engineering
The process of using domain knowledge to create/select/transform input features that make ML algorithms work better. Common techniques: - One-hot encoding for categorical features - Normalization/standardization for numerical features -…
5. Handling Imbalanced Data
Imbalanced data = unequal instances across classes (e.g., 10 malignant vs 90 benign samples in disease detection). Most classification algorithms are sensitive to class imbalance — a model predicting "benign" for everything would get 90%…
Strategies
| Strategy | How It Works | Trade-off | |----------|-------------|-----------| | Under-sampling | Randomly remove majority class samples to match minority | Simple, but loses potentially relevant information | | Over-sampling | Duplicate…
SMOTE (Synthetic Minority Over-sampling Technique)
Instead of simply duplicating minority samples, SMOTE creates new synthetic samples by interpolating between existing minority examples: Key insight: Synthetic examples are plausible because they're created close to existing minority exa…
Critical Rule for Cross-Validation
Never apply over/under-sampling before the train-test split. Apply sampling only to the training fold within each cross-validation iteration. The test fold must remain untouched (original distribution) for honest evaluation. Why this mat…
6. Generative AI
Generative AI creates new content (images, text, music, code) by learning patterns from existing data. It's one of the most significant recent advances in AI.
How It Works
Generative AI pits two neural networks against each other to produce new and original digital works based on sample inputs.
Generative Adversarial Networks (GANs)
| Component | Role | |-----------|------| | Generator | Creates fake samples trying to fool the discriminator | | Discriminator | Tries to distinguish real data from generator's fakes | | Training | Both improve adversarially until gener…
6. Cloud ML Stack (Service Layers)
Modern cloud platforms organize ML services into three layers: | Layer | Expertise Needed | Customization | Use Case | |-------|-----------------|---------------|----------| | AI Services | None (API call) | Low (pre-trained) | Quick int…
7. ML in System Design Interviews
When ML comes up in system design: | System | ML Application | Approach | |--------|---------------|----------| | News Feed | Content ranking | Supervised (engagement prediction) | | Search Engine | Query understanding, result ranking |…
8. Data Versioning for ML
ML projects need to version both code AND data (training datasets, model weights). Standard git doesn't handle large binary files well. Data Version Control (DVC): - Git extension for managing code + data together - Stores large files in…
9. Code Quality in ML Projects
Code Review Checklist
Architecture/Design: - Single Responsibility Principle (one class/method = one job) - Open/Closed Principle (extend, don't modify) - Code duplication ("three strikes" rule — refactor after 3rd copy) - Potential off-by-one errors and loop…
Summary
| Concept | Key Takeaway | |---------|-------------| | Supervised | Labeled data → predict outcomes (classification/regression) | | Unsupervised | No labels → discover structure (clustering/reduction) | | Reinforcement | Trial and error…