Introduction to Machine Learning
Understand the fundamentals of machine learning, its primary types (supervised, unsupervised, reinforcement), and the end‑to‑end workflow from data preparation to model deployment.
Summary
Read Summary
Flashcards
Save Flashcards
Quiz
Take Quiz
Quick Practice
Where are the patterns discovered by a Machine Learning algorithm encoded?
1 of 17
Summary
Machine Learning Overview
What is Machine Learning?
Machine learning is a branch of computer science that focuses on creating systems that improve their performance on a task through experience rather than explicit programming. Instead of writing out every rule a program should follow, we feed a machine learning algorithm data and let it automatically discover the patterns and relationships within that data.
Here's the key distinction: traditional computer programs follow hand-coded instructions ("if the email contains 'Nigeria,' mark it as spam"). Machine learning systems learn patterns from examples ("here are 1,000 emails labeled as spam or not spam—find the patterns yourself").
Once a machine learning algorithm learns these patterns during training, it encodes them in model parameters—adjustable numbers that capture what the model has learned. The trained model can then make predictions or decisions on new data it has never seen before.
Why does this matter? Some tasks are too complex to code manually (like recognizing faces), too numerous to hardcode rules for (like detecting fraud across millions of transactions), or require adapting to new situations (like adjusting credit scoring as the economy changes).
The Three Types of Machine Learning
Machine learning problems fall into three major categories based on the type of data available and the learning goal.
Supervised Learning
In supervised learning, your training data includes both inputs and their correct outputs—we call these outputs labels. Think of it like learning with a teacher who tells you the right answer.
The algorithm's job is to learn a mapping from inputs to outputs so that it can predict the label for new, unseen inputs.
Common examples:
Email spam detection: Input is an email, label is "spam" or "not spam"
House price prediction: Input is house features (size, bedrooms, location), label is the actual sale price
Medical diagnosis: Input is patient symptoms/test results, label is the diagnosis
Image classification: Input is a photo, label is the object it contains ("cat," "dog," "car")
The left side of the image above shows supervised learning: you have labeled examples (one class shown as squares, another as triangles), and you're learning to classify new items.
Unsupervised Learning
In unsupervised learning, your data contains only inputs with no labels telling you what the "right answer" is. The goal shifts: instead of predicting a specific output, you're trying to discover structure in the data itself.
Clustering is a common unsupervised technique that groups similar items together without using labeled examples. If you give a clustering algorithm customer purchase histories without telling it what groups should exist, it might automatically discover clusters like "budget shoppers," "premium buyers," and "seasonal purchasers."
Dimensionality reduction is another unsupervised approach that creates a more compact representation of high-dimensional data. For example, principal component analysis takes data with many features and compresses it into fewer, more informative features while preserving the important patterns.
The right side of img2 above shows unsupervised learning: you have data points but no labels, and you're discovering that they naturally form clusters.
Reinforcement Learning
Reinforcement learning is fundamentally different from the other two. Here, an agent interacts with an environment and receives rewards or penalties for its actions. The agent's goal is to learn a policy—a strategy for making decisions—that maximizes its cumulative reward over time.
This mirrors how humans and animals learn: you try an action, observe the outcome, and adjust future behavior based on whether you received a reward or penalty. A robot learning to walk, a game AI learning to play chess, or a trading algorithm learning investment decisions all use reinforcement learning.
<extrainfo>
The key difference from supervised learning: you don't have explicit "correct answers." Instead, the agent learns by trial and error, receiving feedback signals (rewards) that guide learning.
</extrainfo>
The Machine Learning Workflow
A typical machine learning project follows a structured pipeline with distinct phases:
Data Collection and Preprocessing
Everything starts with data. You collect relevant examples for your problem—historical emails for spam detection, historical house sales for price prediction, or patient records for diagnosis.
Raw data is rarely perfect. Preprocessing involves:
Cleaning: Fixing errors, removing duplicates, handling inconsistencies
Normalizing features: Scaling different features to comparable ranges (if age ranges 0–100 but income ranges 0–1,000,000, they need scaling)
Handling missing values: Deciding whether to remove rows with missing data, estimate missing values, or use algorithms that handle them
Quality preprocessing directly improves model performance. Garbage in = garbage out.
Model Selection
You must choose an algorithm appropriate for your problem. Some common choices include:
Linear regression: For predicting continuous numeric values with linear relationships
Decision trees: For both classification and regression, with interpretable rules
Neural networks: For complex, nonlinear patterns (especially in images, text, or audio)
Support vector machines: For classification with clear decision boundaries
The "best" model depends on your problem type (supervised vs. unsupervised), data characteristics, available computational resources, and whether interpretability matters.
Training the Model
Training means adjusting the model's parameters to fit the training data. The algorithm uses a loss function—a mathematical measure of how wrong the model's predictions are—and iteratively updates parameters to minimize this loss.
Think of it like tuning a guitar: you adjust each string slightly and listen to whether it sounds better, repeating until the sound is right. The algorithm does this automatically, usually thousands of times per second.
Evaluation
Here's a critical point many beginners miss: you never evaluate on your training data. You must use separate validation or test data that the model has never seen. Otherwise, you're like a student memorizing exam answers instead of learning concepts—you won't know if the model truly learned patterns or just memorized the training examples.
Several metrics quantify model performance:
Accuracy: Proportion of correct predictions. Useful for balanced datasets, but misleading for imbalanced ones (if 99% of transactions are legitimate, a model that always predicts "legitimate" is 99% accurate but useless).
Precision: Of all the positive predictions the model made, what proportion were actually correct? Important when false positives are costly (falsely accusing someone of fraud).
Recall: Of all actual positive cases, what proportion did the model correctly identify? Important when false negatives are costly (missing an actual fraud case).
Mean Squared Error (MSE): $MSE = \frac{1}{n}\sum{i=1}^{n}(yi - \hat{y}i)^2$ measures average squared difference between predicted and true values for regression problems. It penalizes larger errors more heavily.
Deployment
Once you have a working model, deployment means integrating it into a real-world system for practical use. This requires:
Making predictions fast and reliably
Monitoring performance (does it still work well on new data?)
Updating the model periodically with new data
Ensuring it scales to handle production traffic
Key Challenges and Considerations
Data Quality and Bias
Your model can only be as good as your training data. Biased training data leads to biased models. If a hiring algorithm is trained on historical hiring decisions from a company with discriminatory past practices, it will learn and perpetuate those biases.
Examples of data bias include:
Historical data reflecting past discrimination
Underrepresentation of certain groups in training data
Data collection methods that systematically exclude certain populations
These issues aren't technical problems you solve with better algorithms—they require careful data collection and active bias detection.
Model Interpretability
Some models are "black boxes." A deep neural network might make accurate predictions, but explaining why it made a specific decision is extremely difficult.
This creates problems:
Trust: How can you trust a model if you don't understand its reasoning?
Accountability: If a model denies someone a loan, can you explain why?
Debugging: If the model performs poorly, you can't understand what went wrong
Regulatory compliance: Some regulations require explainability
There's often a tradeoff: simpler, interpretable models (like decision trees) may be less accurate than complex models (like deep neural networks).
<extrainfo>
Ethical and Societal Impact
Machine learning increasingly affects people's lives—determining credit scores, medical diagnoses, criminal sentencing recommendations, job hiring, and more. Understanding ML concepts helps you evaluate whether systems are fair, whether they could harm certain groups, and whether their use is ethically justified. This is beyond the scope of introductory technical content but crucial for responsible practice.
</extrainfo>
Flashcards
Where are the patterns discovered by a Machine Learning algorithm encoded?
In the model parameters.
What two components are included in the training data for Supervised Learning?
Inputs and correct outputs (labels).
What is the primary goal of a Supervised Learning algorithm when processing a new input?
To predict the label by learning a mapping from inputs to outputs.
What is the defining characteristic of the data used in Unsupervised Learning?
It contains only inputs with no explicit labels.
What is the main objective of Unsupervised Learning?
To discover structure in the data.
Which Unsupervised Learning technique groups similar items together without labels?
Clustering.
In Reinforcement Learning, how does the agent learn from the environment?
By receiving rewards or penalties for its actions.
What is the agent in Reinforcement Learning trying to maximize?
Cumulative reward.
What is the term for the decision-making strategy learned by a Reinforcement Learning agent?
A policy.
What mathematical objective is used to fit model parameters to the training data?
Minimizing a loss function.
What is the goal of iteratively updating parameters during the training process?
To reduce prediction error.
What type of data should be used to evaluate a model's performance?
Separate validation or test data not seen during training.
What does the Accuracy metric represent?
The proportion of correct predictions.
What does the Precision metric represent?
The proportion of positive predictions that are truly positive.
What does the Recall metric represent?
The proportion of actual positives that are correctly identified.
What does Mean-square error ($MSE$) calculate?
The average squared difference between predicted and true numeric values.
What is required after a model is integrated into a real-world system?
Monitoring performance and potentially updating the model with new data.
Quiz
Introduction to Machine Learning Quiz Question 1: In supervised learning, what does the training data contain that distinguishes it from unsupervised learning?
- Both inputs and their corresponding correct outputs (labels) (correct)
- Only input features with no output information
- Only target labels without any input features
- Randomly generated data without any real structure
Introduction to Machine Learning Quiz Question 2: What is the first step in a typical machine learning workflow?
- Collecting data (correct)
- Training the model
- Deploying the model
- Evaluating model performance
Introduction to Machine Learning Quiz Question 3: In model evaluation, what does accuracy represent?
- The proportion of predictions that are correct. (correct)
- The ratio of true positive predictions to all positive predictions.
- The average squared difference between predicted and actual values.
- The proportion of positive predictions that are actually positive.
Introduction to Machine Learning Quiz Question 4: What does a machine learning algorithm automatically discover when given a training set?
- Patterns or relationships in the data (correct)
- Explicit hand‑coded rules
- Optimal hardware configurations
- User authentication credentials
Introduction to Machine Learning Quiz Question 5: During training, what is typically minimized to fit a model’s parameters to the data?
- A loss (error) function (correct)
- The size of the dataset
- The number of input features
- The model’s interpretability score
In supervised learning, what does the training data contain that distinguishes it from unsupervised learning?
1 of 5
Key Concepts
Machine Learning Fundamentals
Machine learning
Supervised learning
Unsupervised learning
Reinforcement learning
Model Development Process
Data preprocessing
Model selection
Model training
Model evaluation
Model interpretability
Ethics in AI
Ethical AI
Definitions
Machine learning
A branch of computer science that creates systems which improve performance on tasks through experience rather than explicit programming.
Supervised learning
A type of machine learning that uses labeled training data to learn a mapping from inputs to outputs for prediction.
Unsupervised learning
A machine‑learning approach that discovers hidden structure in unlabeled data, such as clustering or dimensionality reduction.
Reinforcement learning
An area of machine learning where an agent interacts with an environment, receiving rewards or penalties to learn optimal decision policies.
Data preprocessing
The set of techniques for cleaning, normalizing, and transforming raw data before it is used to train a machine‑learning model.
Model selection
The process of choosing an appropriate algorithm or architecture (e.g., linear regression, decision tree, neural network) based on the problem and data characteristics.
Model training
The procedure of fitting a model’s parameters to training data by minimizing a loss function through iterative optimization.
Model evaluation
The assessment of a trained model’s performance on unseen data using metrics such as accuracy, precision, recall, or mean‑square error.
Model interpretability
The degree to which the internal mechanics and predictions of a machine‑learning model can be understood by humans.
Ethical AI
The study and practice of ensuring artificial intelligence systems are fair, transparent, and socially responsible, addressing bias, accountability, and societal impact.