PPT Machine Learning
UNIT 1
Learning - types of learning
Machine learning (ML) is broadly classified into four main types based on how the model learns from data.
1. Supervised Learning
In supervised learning, the model is trained using labeled data, where both the input and the correct output are provided. The goal is to learn the relationship between inputs and outputs so it can predict outcomes for new data.
Examples:
- Email spam detection
- House price prediction
- Disease diagnosis
Common algorithms:
- Linear Regression
- Logistic Regression
- Decision Trees
- Support Vector Machine (SVM)
- Random Forest
- Neural Networks
Example:
A model learns from past house prices and predicts the price of a new house.
2. Unsupervised Learning
In unsupervised learning, the model is trained using unlabeled data. It tries to discover hidden patterns or group similar data points.
Examples:
- Customer segmentation
- Market basket analysis
- Fraud detection
Common algorithms:
- K-Means Clustering
- Hierarchical Clustering
- DBSCAN
- Principal Component Analysis (PCA)
Example:
Grouping customers into different categories based on their purchasing behavior.
3. Semi-Supervised Learning
Semi-supervised learning uses a small amount of labeled data and a large amount of unlabeled data. It is useful when labeling data is expensive or time-consuming.
Examples:
- Image recognition
- Speech recognition
- Medical image analysis
Example:
Training a model with a few labeled medical images and thousands of unlabeled images.
4. Reinforcement Learning
In reinforcement learning, an agent learns by interacting with an environment. It receives rewards for good actions and penalties for bad actions, improving its decisions over time.
Examples:
- Self-driving cars
- Game-playing AI
- Robot navigation
Common algorithms:
- Q-Learning
- Deep Q Networks (DQN)
- Policy Gradient Methods
Example:
A robot learns to navigate a maze by receiving rewards for reaching the goal.
Summary Table
| Learning Type | Training Data | Goal | Example |
|---|---|---|---|
| Supervised Learning | Labeled | Predict outputs | Spam email detection |
| Unsupervised Learning | Unlabeled | Find patterns/groups | Customer segmentation |
| Semi-Supervised Learning | Partially labeled | Improve accuracy with limited labels | Image classification |
| Reinforcement Learning | Reward/Penalty feedback | Learn optimal actions | Self-driving cars, game AI |
The Brain and the Neuron
The human brain is the body's control center. It processes information, makes decisions, stores memories, and controls actions. The basic functional unit of the brain is the neuron (nerve cell), which communicates with other neurons through electrical and chemical signals.
Biological Neuron vs Artificial Neuron
| Biological Neuron | Artificial Neuron (AI) |
|---|---|
| Receives signals through dendrites | Receives input features |
| Cell body processes signals | Computes weighted sum of inputs |
| Axon sends output signal | Produces output value |
| Synapse controls signal strength | Weights determine connection strength |
| Learns by changing synaptic strength | Learns by updating weights during training |
Design of a Learning System
A learning system in machine learning is a framework that enables a computer to learn from data and improve its performance over time without being explicitly programmed for every task.
Definition
A learning system is a combination of data, algorithms, and evaluation methods that learns patterns from past experience and uses them to make predictions or decisions on new data.
Components of a Learning System
Real-World Problem │ ▼ Data Collection │ ▼ Data Preprocessing │ ▼ Feature Engineering │ ▼ Machine Learning Model │ ▼ Model Training │ ▼ Model Evaluation │ ▼ Prediction │ ▼ Performance Feedback │ ▼ Model Improvement
Step 1: Problem Definition
Clearly identify the objective.
Examples:
- Predict house prices.
- Detect spam emails.
- Recognize handwritten digits.
- Predict customer churn.
Step 2: Data Collection
Gather relevant data from various sources.
Sources:
- Databases
- Sensors
- Websites
- APIs
- Surveys
- IoT devices
Example:
For house price prediction:
- Area
- Number of bedrooms
- Location
- Age of house
- Price
Step 3: Data Preprocessing
Prepare the data before training.
Tasks include:
- Remove duplicate records.
- Handle missing values.
- Normalize or standardize features.
- Encode categorical variables.
- Split data into training and testing sets.
Step 4: Feature Engineering
Select or create the most informative features.
Examples:
- House size
- Number of rooms
- Distance to city center
- Age of building
Good features improve model accuracy.
Step 5: Choose a Learning Algorithm
Select an algorithm based on the problem.
| Problem Type | Algorithms |
|---|---|
| Classification | Logistic Regression, Decision Tree, Random Forest, SVM |
| Regression | Linear Regression, Random Forest Regressor |
| Clustering | K-Means, DBSCAN |
| Deep Learning | CNN, RNN, Transformers |
Step 6: Model Training
The model learns patterns from the training data by adjusting its parameters to reduce prediction errors.
Training Inputs:
- Features (X)
- Labels (Y)
The learning algorithm finds the relationship between inputs and outputs.
Step 7: Model Evaluation
Test the trained model using unseen data.
Classification Metrics
- Accuracy
- Precision
- Recall
- F1 Score
- ROC-AUC
Regression Metrics
- MAE (Mean Absolute Error)
- MSE (Mean Squared Error)
- RMSE (Root Mean Squared Error)
- R² Score
Step 8: Prediction
Use the trained model to make predictions on new data.
Example:
Input:
- Area = 1500 sq ft
- Bedrooms = 3
Output:
- Predicted Price = ₹60,00,000
Step 9: Feedback and Improvement
Monitor performance and improve the system by:
- Collecting more data.
- Retraining the model.
- Tuning hyperparameters.
- Updating features.
- Choosing a better algorithm.
This continuous cycle helps the system adapt and improve over time.
Characteristics of a Good Learning System
- Accuracy: Produces correct predictions.
- Generalization: Performs well on unseen data.
- Scalability: Handles large datasets efficiently.
- Robustness: Works reliably even with noisy or incomplete data.
- Efficiency: Uses computational resources effectively.
Example: Email Spam Detection Learning System
Emails │ ▼ Data Collection │ ▼ Preprocessing (Remove punctuation, tokenize text) │ ▼ Feature Extraction (Bag of Words / TF-IDF) │ ▼ Train Classifier (Naive Bayes / Logistic Regression) │ ▼ Evaluate Accuracy │ ▼ Predict Spam or Not Spam
Applications of Learning Systems
- Medical diagnosis
- Fraud detection
- Recommendation systems
- Self-driving cars
- Face recognition
- Speech recognition
- Stock price prediction
- Predictive maintenance
- Customer churn prediction
Advantages
- Learns automatically from data.
- Improves performance with more experience.
- Reduces manual effort.
- Can solve complex real-world problems.
- Supports data-driven decision-making.
Limitations
- Requires high-quality data.
- Training can be time-consuming.
- May overfit or underfit if not properly designed.
- Performance depends on the choice of algorithm and features.
Summary
A machine learning system follows a structured process:
- Define the problem.
- Collect data.
- Preprocess the data.
- Engineer/select features.
- Choose a suitable algorithm.
- Train the model.
- Evaluate its performance.
- Make predictions.
- Continuously improve using feedback.
Perspectives and Issues in Machine Learning
Introduction
Machine Learning (ML) is a branch of Artificial Intelligence (AI) that enables computers to learn from data and improve their performance without being explicitly programmed. While ML has transformed industries such as healthcare, finance, education, and transportation, it also presents several technical, ethical, and practical challenges.
Perspectives of Machine Learning
A perspective refers to the different ways machine learning is viewed and applied.
1. Computational Perspective
- Focuses on developing algorithms that learn from data efficiently.
- Aims to improve prediction accuracy while reducing computation time.
Example: Developing faster algorithms for image recognition.
2. Statistical Perspective
- Machine learning is viewed as a statistical method for analyzing data.
- Uses probability and statistical models to make predictions.
Example: Predicting house prices using regression analysis.
3. Artificial Intelligence Perspective
- ML is considered a subset of AI.
- Helps machines make intelligent decisions based on experience.
Example: Virtual assistants like Siri or Google Assistant.
4. Data Science Perspective
- ML is used to discover patterns and insights from large datasets.
- Supports data-driven decision-making.
Example: Customer segmentation for targeted marketing.
5. Business Perspective
- Organizations use ML to improve efficiency, reduce costs, and increase profits.
Applications:
- Sales forecasting
- Recommendation systems
- Fraud detection
- Demand prediction
6. Human-Centered Perspective
- Focuses on developing ML systems that are fair, transparent, and beneficial to people.
- Emphasizes user trust and ethical AI.
Example: AI systems that explain why a loan application was approved or rejected.
Issues in Machine Learning
1. Data Quality
Machine learning models rely heavily on data quality.
Problems:
- Missing values
- Duplicate records
- Noisy data
- Incorrect labels
Solution:
- Data cleaning
- Data preprocessing
- Data validation
2. Overfitting
Overfitting occurs when a model learns the training data too well, including its noise, and performs poorly on new data.
Characteristics:
- High training accuracy
- Low testing accuracy
Solutions:
- Cross-validation
- Regularization
- More training data
- Simpler models
3. Underfitting
Underfitting happens when a model is too simple to capture patterns in the data.
Characteristics:
- Low training accuracy
- Low testing accuracy
Solutions:
- Use a more complex model
- Add relevant features
- Train for more iterations
4. Bias and Fairness
Bias occurs when the training data or algorithm produces unfair predictions.
Example:
A hiring model trained on biased historical data may unfairly favor certain candidates.
Solutions:
- Use diverse datasets
- Detect and reduce bias
- Regularly audit model performance
5. Data Privacy and Security
Many ML applications use sensitive personal information.
Challenges:
- Protecting user privacy
- Preventing unauthorized access
- Complying with data protection laws
Solutions:
- Encryption
- Data anonymization
- Secure data storage
- Access control
6. Model Interpretability
Some models, especially deep learning models, are difficult to understand.
Challenge:
Users may not know why a prediction was made.
Solutions:
- Explainable AI (XAI)
- Feature importance analysis
- Model visualization techniques
7. Computational Cost
Training advanced ML models often requires significant computational resources.
Challenges:
- High processing time
- Expensive hardware (GPUs/TPUs)
- Large memory requirements
Solutions:
- Cloud computing
- Efficient algorithms
- Model optimization
8. Lack of Training Data
Some applications have limited labeled data.
Solutions:
- Data augmentation
- Transfer learning
- Semi-supervised learning
- Synthetic data generation
9. Feature Selection
Choosing irrelevant features can reduce model performance.
Solutions:
- Feature engineering
- Principal Component Analysis (PCA)
- Recursive Feature Elimination (RFE)
10. Continuous Model Maintenance
Data patterns can change over time (known as concept drift).
Solutions:
- Monitor model performance
- Retrain with updated data
- Update features periodically
Advantages of Machine Learning
- Automates decision-making
- Improves prediction accuracy
- Learns from experience
- Handles large datasets
- Supports personalized services
- Enables intelligent automation
Limitations of Machine Learning
- Requires large amounts of quality data
- Can be computationally expensive
- May produce biased predictions
- Difficult to interpret complex models
- Needs regular maintenance and updates
- Performance depends on data quality
Applications
- Healthcare (disease diagnosis)
- Finance (fraud detection)
- Retail (recommendation systems)
- Manufacturing (predictive maintenance)
- Agriculture (crop yield prediction)
- Transportation (autonomous vehicles)
- Education (personalized learning)
Summary Table
| Perspective | Description | Example |
|---|---|---|
| Computational | Efficient learning algorithms | Image recognition |
| Statistical | Prediction using probability | House price prediction |
| AI | Intelligent decision-making | Virtual assistants |
| Data Science | Knowledge discovery from data | Customer segmentation |
| Business | Improve efficiency and profit | Sales forecasting |
| Human-Centered | Fair, transparent, ethical AI | Explainable loan approval |
| Issue | Impact | Solution |
|---|---|---|
| Poor Data Quality | Low accuracy | Data cleaning |
| Overfitting | Poor generalization | Regularization, cross-validation |
| Underfitting | Weak performance | Better models, more features |
| Bias | Unfair decisions | Fair datasets, bias mitigation |
| Privacy | Data misuse risk | Encryption, anonymization |
| Interpretability | Hard to explain predictions | Explainable AI (XAI) |
| High Computational Cost | Slow and expensive training | Cloud computing, optimization |
| Limited Data | Reduced performance | Data augmentation, transfer learning |
| Feature Selection | Lower accuracy | Feature engineering, PCA |
| Concept Drift | Performance degrades over time | Monitoring and retraining |
Key Points
- Perspectives describe different viewpoints of machine learning, such as computational, statistical, AI, business, and ethical perspectives.
- Issues include challenges like poor data quality, overfitting, underfitting, bias, privacy concerns, interpretability, computational cost, limited data, feature selection, and concept drift.
- Addressing these issues is essential for building reliable, accurate, and trustworthy machine learning systems.
Concept Learning Task and Concept Learning as Search
1. Concept Learning
Concept learning is a machine learning task in which a computer learns a concept (or rule) from a set of training examples. The goal is to determine whether a new example belongs to a particular category.
Definition
Concept Learning is the process of inferring a general rule or function from a set of positive and negative training examples.
Example
Suppose we want to learn the concept "Play Tennis."
| Weather | Temperature | Humidity | Wind | Play Tennis |
|---|---|---|---|---|
| Sunny | Warm | Normal | Weak | Yes |
| Sunny | Cold | High | Strong | No |
| Rainy | Warm | High | Weak | Yes |
| Cloudy | Warm | Normal | Strong | Yes |
The machine learns a rule such as:
Rule:
If Weather is Sunny or Cloudy, Temperature is Warm, and Wind is Weak, then Play Tennis = Yes.
It can then classify new examples based on the learned concept.
Components of a Concept Learning Task
A concept learning task consists of the following components:
1. Instance Space (X)
The set of all possible examples.
Example:
- Weather
- Temperature
- Humidity
- Wind
2. Target Concept (C)
The function that correctly classifies every instance.
Example:
Play Tennis = Yes or No
3. Hypothesis (H)
A hypothesis is a possible rule describing the target concept.
Example:
IF Weather = Sunny AND Temperature = Warm THEN Play Tennis = Yes
4. Training Examples (D)
A collection of labeled examples used for learning.
Example:
| Example | Class |
|---|---|
| Sunny, Warm | Positive |
| Rainy, Cold | Negative |
5. Learning Algorithm
The algorithm searches for the hypothesis that best fits the training data.
Examples:
- Find-S Algorithm
- Candidate Elimination Algorithm
- Decision Tree Learning
Steps in Concept Learning
- Collect training examples.
- Define the target concept.
- Select a hypothesis space.
- Apply a learning algorithm.
- Evaluate the learned hypothesis.
- Predict the class of new instances.
Concept Learning as Search
Concept learning can be viewed as a search problem.
The learning algorithm searches through a hypothesis space to find the hypothesis that best matches the training examples.
Search Process
Training Examples │ ▼ Hypothesis Space (H1, H2, H3, H4, ...) │ ▼ Search Algorithm │ ▼ Best Hypothesis │ ▼ Prediction
Hypothesis Space
The hypothesis space (H) is the set of all possible hypotheses that the learning algorithm can consider.
Example:
For weather data:
H1 : Weather = Sunny H2 : Weather = Sunny AND Temperature = Warm H3 : Weather = Sunny AND Wind = Weak H4 : TRUE
The algorithm searches among these hypotheses to find the one that best explains the training data.
Search Strategies
1. General-to-Specific Search
- Starts with the most general hypothesis.
- Gradually adds conditions to specialize it.
Example:
H0 : Any weather ↓ Sunny ↓ Sunny AND Warm ↓ Sunny AND Warm AND Weak Wind
2. Specific-to-General Search
- Starts with the most specific hypothesis.
- Gradually removes restrictions to generalize it.
Example:
Sunny, Warm, Normal, Weak ↓ Sunny, Warm, ?, Weak ↓ Sunny, ?, ?, ? ↓ Any Weather
Version Space
The Version Space is the set of all hypotheses that are consistent with the training examples.
It is bounded by:
- Specific Boundary (S): The most specific consistent hypothesis.
- General Boundary (G): The most general consistent hypothesis.
Any hypothesis between S and G is considered consistent with the observed data.
Example of Concept Learning as Search
Training Data
| Weather | Temperature | Play |
|---|---|---|
| Sunny | Warm | Yes |
| Sunny | Cold | No |
| Rainy | Warm | No |
Initial Hypothesis
<?, ?>
(All values allowed)
After Learning
<Sunny, Warm>
The search algorithm has identified the hypothesis that correctly classifies the given training examples.
Applications of Concept Learning
- Email spam detection
- Medical diagnosis
- Product recommendation
- Face recognition
- Credit approval
- Fault detection
- Customer classification
Advantages
- Learns general rules from examples.
- Improves prediction accuracy over time.
- Provides interpretable decision rules.
- Forms the basis for many supervised learning algorithms.
Limitations
- Requires representative labeled training data.
- Large hypothesis spaces can make search computationally expensive.
- Noisy or inconsistent data can reduce accuracy.
- May struggle with highly complex concepts without advanced models.
Difference Between Concept Learning Task and Concept Learning as Search
| Concept Learning Task | Concept Learning as Search |
|---|---|
| Focuses on learning a target concept from labeled examples. | Views learning as searching through a hypothesis space. |
| Uses training data to infer a rule. | Uses search strategies to identify the best hypothesis. |
| Includes instances, hypotheses, and target concepts. | Includes hypothesis space, search algorithm, and evaluation. |
| Goal is accurate classification of new examples. | Goal is finding the hypothesis most consistent with the training data. |
Key Points
- Concept Learning is the process of learning a classification rule from labeled examples.
- A concept learning task includes the instance space, target concept, hypothesis space, training examples, and learning algorithm.
- Concept learning as search treats learning as a search through the hypothesis space to find the hypothesis that best matches the training data.
- Important related ideas include the hypothesis space, version space, general-to-specific search, and specific-to-general search.
Finding a Maximally Specific Hypothesis (Find-S Algorithm)
Introduction
The Find-S Algorithm is one of the simplest algorithms used in concept learning. It finds the most specific hypothesis that is consistent with all positive training examples.
Definition
A maximally specific hypothesis is the most restrictive hypothesis that correctly classifies all positive training examples while excluding as many negative examples as possible.
The algorithm starts with the most specific hypothesis and gradually generalizes it only when necessary.
Basic Idea
- Start with the most specific hypothesis (no instance is accepted).
- Examine each positive example.
- If the hypothesis does not cover the example, generalize it minimally.
- Ignore all negative examples.
Steps of the Find-S Algorithm
- Initialize the hypothesis to the most specific possible.
-
For each training example:
- If it is negative, ignore it.
-
If it is positive:
- Compare it with the current hypothesis.
- If an attribute differs, replace that attribute with ? (meaning "any value").
- Continue until all positive examples have been processed.
- The final hypothesis is the maximally specific hypothesis.
Algorithm
Find-S(H, D) 1. Initialize H to the most specific hypothesis. 2. For each positive training example x: For each attribute a: If H[a] is empty: H[a] = x[a] Else if H[a] ≠ x[a]: H[a] = ? 3. Return H.
Example
Suppose we have the following training data.
| Example | Sky | AirTemp | Humidity | Wind | Water | Forecast | Enjoy Sport |
|---|---|---|---|---|---|---|---|
| 1 | Sunny | Warm | Normal | Strong | Warm | Same | Yes |
| 2 | Sunny | Warm | High | Strong | Warm | Same | Yes |
| 3 | Rainy | Cold | High | Strong | Warm | Change | No |
| 4 | Sunny | Warm | High | Strong | Cool | Change | Yes |
Step 1: Initial Hypothesis
H0 = <Ø, Ø, Ø, Ø, Ø, Ø>
(Ø means the most specific value.)
Step 2: Process Example 1 (Positive)
Example:
<Sunny, Warm, Normal, Strong, Warm, Same>
Update hypothesis:
H1 = <Sunny, Warm, Normal, Strong, Warm, Same>
Step 3: Process Example 2 (Positive)
Example:
<Sunny, Warm, High, Strong, Warm, Same>
Only Humidity differs.
H2 = <Sunny, Warm, ?, Strong, Warm, Same>
Step 4: Process Example 3 (Negative)
Negative examples are ignored.
H3 = <Sunny, Warm, ?, Strong, Warm, Same>
Step 5: Process Example 4 (Positive)
Example:
<Sunny, Warm, High, Strong, Cool, Change>
Differences:
-
Water →
? -
Forecast →
?
Final hypothesis:
H4 = <Sunny, Warm, ?, Strong, ?, ?>
Final Maximally Specific Hypothesis
<Sunny, Warm, ?, Strong, ?, ?>
This means:
- Sky must be Sunny
- Air Temperature must be Warm
- Humidity can be any value
- Wind must be Strong
- Water can be any value
- Forecast can be any value
Flowchart
Start │ ▼ Initialize Most Specific Hypothesis │ ▼ Read Training Example │ ▼ Positive? ┌───────┐ │ No │──► Ignore └───────┘ │ Yes │ ▼ Generalize Hypothesis │ ▼ More Examples? │ Yes ─────► Repeat │ ▼ Return Final Hypothesis
Advantages
- Easy to understand and implement.
- Efficient for simple concept-learning problems.
- Produces the most specific hypothesis consistent with positive examples.
- Useful for introducing concept learning.
Disadvantages
- Ignores negative examples, so it may produce overly general hypotheses.
- Assumes training data is noise-free.
- Cannot determine whether multiple hypotheses fit the data equally well.
- Limited to conjunctive hypothesis spaces.
Applications
- Medical diagnosis
- Email spam detection
- Product recommendation
- Fault detection
- Pattern recognition
- Student performance prediction
Summary
| Feature | Description |
|---|---|
| Algorithm | Find-S |
| Learning Type | Supervised Learning |
| Uses Positive Examples | Yes |
| Uses Negative Examples | No |
| Starting Point | Most Specific Hypothesis |
| Goal | Find the maximally specific hypothesis consistent with all positive examples |
Key Points
- Find-S begins with the most specific hypothesis.
- It updates only using positive training examples.
-
When an attribute differs across positive examples, it is replaced with
?to generalize just enough. - The final result is the maximally specific hypothesis that covers all observed positive examples.
Version Spaces and the Candidate Elimination Algorithm
Introduction
Version Space and the Candidate Elimination Algorithm are important concepts in concept learning. Unlike the Find-S algorithm, which finds only one hypothesis, the Candidate Elimination Algorithm maintains all hypotheses that are consistent with the training data.
Version Space
Definition
A Version Space is the set of all hypotheses in the hypothesis space that are consistent with every training example.
Mathematically,
where:
- H = Hypothesis space
- h = A hypothesis
Representation of Version Space
A Version Space is represented by two boundaries:
1. Specific Boundary (S)
- Contains the most specific hypothesis consistent with the training data.
- Initially, it is the most restrictive hypothesis.
2. General Boundary (G)
- Contains the most general hypothesis consistent with the training data.
- Initially, it accepts every instance.
Version Space General Boundary (G) │ ▼ -------------------------- | All Consistent Rules | -------------------------- ▲ │ Specific Boundary (S)
Candidate Elimination Algorithm
Definition
The Candidate Elimination Algorithm is a concept learning algorithm that updates the Specific (S) and General (G) boundaries whenever a new training example is processed.
It eliminates hypotheses that are inconsistent with the training examples until only the consistent hypotheses remain.
Initial Boundaries
Suppose the attributes are:
- Sky
- AirTemp
- Humidity
- Wind
- Water
- Forecast
Initially,
Specific Boundary
S0 = <Ø, Ø, Ø, Ø, Ø, Ø>
(Ø represents the most specific hypothesis.)
General Boundary
G0 = <?, ?, ?, ?, ?, ?>
(? represents any value.)
Steps of the Candidate Elimination Algorithm
-
Initialize:
- as the most specific hypothesis.
- as the most general hypothesis.
-
Process each training example:
-
If the example is positive:
- Remove hypotheses from G that do not cover the example.
- Generalize S minimally to include the example.
-
If the example is negative:
- Remove hypotheses from S that cover the negative example.
- Specialize G minimally to exclude the example.
-
If the example is positive:
- Repeat until all training examples are processed.
- The hypotheses between S and G form the Version Space.
Example
Training Data
| Sky | AirTemp | Humidity | Wind | Water | Forecast | Enjoy Sport |
|---|---|---|---|---|---|---|
| Sunny | Warm | Normal | Strong | Warm | Same | Yes |
| Sunny | Warm | High | Strong | Warm | Same | Yes |
| Rainy | Cold | High | Strong | Warm | Change | No |
Step 1: Initial State
S = <Ø, Ø, Ø, Ø, Ø, Ø> G = <?, ?, ?, ?, ?, ?>
Step 2: First Positive Example
<Sunny, Warm, Normal, Strong, Warm, Same>
Update:
S = <Sunny, Warm, Normal, Strong, Warm, Same> G = <?, ?, ?, ?, ?, ?>
Step 3: Second Positive Example
<Sunny, Warm, High, Strong, Warm, Same>
Humidity differs.
S = <Sunny, Warm, ?, Strong, Warm, Same> G = <?, ?, ?, ?, ?, ?>
Step 4: Negative Example
<Rainy, Cold, High, Strong, Warm, Change>
Since G accepts every instance, specialize it to exclude this negative example while still covering the positive examples.
One possible updated general boundary is:
G = { <Sunny, ?, ?, ?, ?, ?>, <?, Warm, ?, ?, ?, ?>, <?, ?, ?, ?, ?, Same> }
The specific boundary remains:
S = <Sunny, Warm, ?, Strong, Warm, Same>
Candidate Elimination Flowchart
Start │ ▼ Initialize S and G │ ▼ Read Training Example │ ▼ Positive Example? ┌──────────────┐ │ Yes │ └──────────────┘ │ Generalize S Remove inconsistent G │ ▼ No │ Specialize G Remove inconsistent S │ ▼ More Examples? │ Yes ─────► Repeat │ ▼ Return Version Space
Difference Between Find-S and Candidate Elimination
| Feature | Find-S | Candidate Elimination |
|---|---|---|
| Uses Positive Examples | Yes | Yes |
| Uses Negative Examples | No | Yes |
| Result | One hypothesis | All consistent hypotheses (Version Space) |
| Maintains S Boundary | Yes | Yes |
| Maintains G Boundary | No | Yes |
| Handles Inconsistent Data | Limited | Better, but assumes noise-free data |
Advantages
- Uses both positive and negative examples.
- Maintains every hypothesis consistent with the training data.
- More informative than Find-S because it tracks the complete version space.
- Helps understand the uncertainty remaining after learning.
Limitations
- Assumes training data is free from noise.
- Can become computationally expensive for large hypothesis spaces.
- Version spaces may grow very large for complex problems.
- Difficult to apply directly to high-dimensional real-world datasets.
Applications
- Concept learning
- Rule-based classification
- Educational demonstrations of machine learning
- Knowledge discovery
- Pattern recognition
Summary
| Concept | Description |
|---|---|
| Version Space | Set of all hypotheses consistent with the training data |
| Specific Boundary (S) | Most specific consistent hypothesis |
| General Boundary (G) | Most general consistent hypotheses |
| Candidate Elimination | Algorithm that updates both S and G after each training example |
Key Points
- A Version Space contains all hypotheses that remain consistent with the observed training data.
- The Specific Boundary (S) stores the most specific consistent hypothesis.
- The General Boundary (G) stores the most general consistent hypotheses.
- The Candidate Elimination Algorithm updates both S and G using positive and negative examples, narrowing the version space until only consistent hypotheses remain.
Linear Discriminants, Perceptron, Linear Separability, and Linear Regression
These are fundamental concepts in Machine Learning and are widely used in classification and prediction problems.
1. Linear Discriminants
Definition
A Linear Discriminant is a function that separates data into different classes using a linear decision boundary (a line in 2D, a plane in 3D, or a hyperplane in higher dimensions).
The discriminant function is:
Where:
- x = Input feature vector
- w = Weight vector
- b = Bias (threshold)
Decision Rule
- If g(x) > 0, classify as Class 1
- If g(x) < 0, classify as Class 2
- If g(x) = 0, the point lies on the decision boundary
Example
Suppose
Then
The line
acts as the decision boundary.
Advantages
- Simple and fast
- Easy to interpret
- Works well for linearly separable data
Limitations
- Cannot classify complex nonlinear datasets accurately
2. Perceptron
Definition
The Perceptron is the simplest neural network model introduced by Frank Rosenblatt (1958). It is a binary classifier that learns a linear decision boundary.
Structure
Inputs (x1, x2, ..., xn) │ ▼ Multiply by Weights (w1, w2, ..., wn) │ ▼ Weighted Sum + Bias │ ▼ Activation Function │ ▼ Output (0 or 1)
Perceptron Equation
where is the step activation function:
Perceptron Learning Algorithm
- Initialize weights randomly or to zero.
-
For each training example:
- Compute the output.
- Compare with the actual label.
- Update weights if the prediction is incorrect.
- Repeat until no errors remain or a stopping criterion is met.
Weight Update Rule
Where:
- = Learning rate
- = Target output
- = Predicted output
Advantages
- Easy to implement
- Fast learning
- Suitable for binary classification
Disadvantages
- Works only for linearly separable data
- Cannot solve XOR and similar nonlinear problems
3. Linear Separability
Definition
A dataset is linearly separable if a single straight line (or hyperplane) can completely separate the classes.
Linearly Separable Data
○ ○ ○ ○ ------------------- × × × ×
A straight line separates both classes perfectly.
Non-Linearly Separable Data
○ × ○ × ○
No single straight line can separate these classes.
Characteristics
Linearly Separable
- One straight line separates classes.
- Perceptron converges successfully.
- High classification accuracy.
Non-Linearly Separable
- No straight line can separate classes.
- Perceptron fails to converge.
- Requires nonlinear models such as kernel SVMs or multilayer neural networks.
4. Linear Regression
Definition
Linear Regression is a supervised learning algorithm used to predict continuous numerical values.
It models the relationship between independent variables and a dependent variable using a straight line.
Simple Linear Regression
Where:
- = Predicted value
- = Input feature
- = Intercept
- = Slope
Multiple Linear Regression
For multiple input variables,
Objective
Find the line that minimizes the prediction error.
The error is commonly measured using the Mean Squared Error (MSE):
Example
Predicting house prices.
| Area (sq ft) | Price (₹ Lakhs) |
|---|---|
| 1000 | 30 |
| 1500 | 45 |
| 2000 | 60 |
The model learns a line that predicts the price for a new house based on its area.
Advantages
- Simple and easy to interpret
- Fast to train
- Effective when the relationship is approximately linear
Limitations
- Assumes a linear relationship
- Sensitive to outliers
- May underperform on complex nonlinear data
Difference Between Perceptron and Linear Regression
| Feature | Perceptron | Linear Regression |
|---|---|---|
| Learning Type | Supervised | Supervised |
| Task | Classification | Regression |
| Output | Class label (0/1) | Continuous value |
| Decision Boundary | Linear | Regression line |
| Activation Function | Step function | None |
| Error Function | Classification error | Mean Squared Error (MSE) |
Difference Between Linear Discriminant and Linear Regression
| Linear Discriminant | Linear Regression |
|---|---|
| Used for classification | Used for prediction of continuous values |
| Produces class labels | Produces numerical values |
| Uses a decision boundary | Fits the best regression line |
| Example: Spam detection | Example: House price prediction |
Applications
Linear Discriminants
- Face recognition
- Email spam detection
- Medical diagnosis
- Document classification
Perceptron
- Binary image classification
- Character recognition
- Pattern recognition
Linear Regression
- House price prediction
- Sales forecasting
- Stock trend analysis
- Weather prediction
Summary
| Concept | Purpose | Output |
|---|---|---|
| Linear Discriminant | Separate classes using a linear boundary | Class label |
| Perceptron | Learn a linear classifier | Binary class (0 or 1) |
| Linear Separability | Property of data that can be separated by a line | Determines whether linear classifiers are suitable |
| Linear Regression | Predict continuous values using a best-fit line | Numerical prediction |
Key Points
- Linear Discriminants classify data using a linear decision boundary.
- Perceptron is the simplest neural network and works only with linearly separable data.
- Linear Separability determines whether a straight line (or hyperplane) can separate different classes.
- Linear Regression predicts continuous values by fitting the best straight line to the data using the least-squares principle.
UNIT 2
A Multilayer Perceptron
A Multilayer Perceptron (MLP) is a type of artificial neural network (ANN) that consists of multiple layers of interconnected neurons. It is one of the most fundamental deep learning models and is widely used for classification and regression tasks.
Structure of an MLP
An MLP has three types of layers:
-
Input Layer
- Receives the input features.
- Each neuron represents one input variable.
-
Hidden Layer(s)
- Perform computations on the inputs.
- An MLP has one or more hidden layers.
-
Each neuron applies:
- A weighted sum of inputs
- A bias
- An activation function (such as ReLU, Sigmoid, or Tanh)
-
Output Layer
- Produces the final prediction.
-
The activation function depends on the task:
- Sigmoid → Binary classification
- Softmax → Multi-class classification
- Linear → Regression
Mathematical Operation
For a neuron:
where:
- = inputs
- = weights
- = bias
- = activation function
- = output of the neuron
Training Process
An MLP learns through the following steps:
- Forward propagation
- Compute loss (error)
- Backpropagation
- Update weights using an optimizer (e.g., Gradient Descent or Adam)
This process is repeated over many training epochs until the model converges.
Common Activation Functions
| Activation | Formula | Use |
|---|---|---|
| ReLU | Hidden layers | |
| Sigmoid | Binary classification | |
| Tanh | Hidden layers | |
| Softmax | Converts outputs to probabilities | Multi-class classification |
Advantages
- Can model complex, non-linear relationships.
- Works well for classification and regression.
- Easy to implement.
- Foundation for many deep learning models.
Limitations
- Requires a large amount of training data for good performance.
- Can overfit without regularization.
- Training can be computationally expensive for deep networks.
- Does not naturally exploit spatial or sequential structure (unlike CNNs or RNNs).
Applications
- Image classification (simple datasets)
- Handwritten digit recognition
- Fraud detection
- Medical diagnosis
- Stock price prediction
- Customer churn prediction
- Sentiment analysis
Example
Suppose you want to classify whether an email is spam or not spam:
- Input layer: Email features (word frequencies, sender information, etc.)
- Hidden layers: Learn patterns that distinguish spam from legitimate emails.
- Output layer: Produces the probability that the email is spam.
In summary, an MLP is a feedforward neural network with one or more hidden layers that learns complex patterns by adjusting weights through backpropagation. It is one of the most important building blocks in modern machine learning and deep learning.
Feedforward and backward propagation (backpropagation)
Feedforward and backward propagation (backpropagation) are the two main phases used to train a neural network such as a Multilayer Perceptron (MLP).
1. Feedforward
In the feedforward phase, the input data moves from the input layer to the output layer to produce a prediction.
Steps
- Input features are given to the input layer.
-
Each neuron computes:
- Weighted sum of inputs
- Adds a bias
- Applies an activation function
- The output of one layer becomes the input to the next layer.
- The final output (prediction) is generated.
Formula
For each neuron:
where:
- = input
- = weight
- = bias
- = activation function
- = neuron output
Example
Input → Hidden Layer → Output 2,3 → [Neuron] → Prediction = 0.85
If the expected output is 1, the network has made an error of:
Error = Actual − Predicted = 1 − 0.85 = 0.15
2. Backward Propagation (Backpropagation)
Backpropagation is the learning phase. It propagates the error backward through the network and adjusts the weights and biases to reduce future errors.
Steps
- Calculate the prediction error using a loss function.
- Compute the gradient (how much each weight contributed to the error).
- Send the error backward from the output layer to the hidden layers.
- Update weights and biases using an optimization algorithm such as Gradient Descent.
Weight Update Formula
where:
- = weight
- = learning rate
- = loss function
- = gradient of the loss with respect to the weight
Flow Diagram
Feedforward Input ─────────► Hidden ─────────► Output │ ▼ Compute Loss │ ▼ Backpropagation (Error Backward) Output ◄──────── Hidden ◄──────── Input Update Weights
Comparison
| Feature | Feedforward | Backpropagation |
|---|---|---|
| Direction | Input → Output | Output → Input |
| Purpose | Produce prediction | Learn by reducing error |
| Uses weights | Yes | Updates weights |
| Calculates | Output values | Gradients and weight updates |
| Occurs | Before loss calculation | After loss calculation |
| Output | Prediction | Improved weights and biases |
Summary
- Feedforward: The network uses the current weights to compute a prediction by passing data from the input layer to the output layer.
- Backpropagation: The network compares the prediction with the correct output, computes the error, and updates the weights by propagating the error backward, enabling the model to improve over successive training iterations.
Backpropagation error
Backpropagation error is the process of calculating how much each neuron contributed to the prediction error and propagating that error backward through the neural network so the weights can be updated.
Steps in Backpropagation Error
-
Forward pass
- The network computes the predicted output.
-
Calculate the error
- Compare the predicted output with the actual (target) output.
-
For a single output neuron:
-
Calculate the loss
- A loss function measures the overall error.
-
Example (Mean Squared Error):
where:
- = Target output
- = Predicted output
-
Propagate the error backward
- Compute the error gradient for the output layer.
- Use the chain rule to determine how much each hidden neuron contributed to the error.
-
Update weights
-
Adjust each weight to reduce the error:
where:
- = Learning rate
- = Gradient of the loss with respect to the weight
-
Error Calculation
Output Layer Error
For an output neuron:
where:
- = Target output
- = Predicted output
- = Derivative of the activation function
Hidden Layer Error
For a hidden neuron:
This means the hidden layer's error depends on:
- The errors in the next layer.
- The weights connecting the hidden neuron to the next layer.
Example
Suppose:
- Target output = 1
- Predicted output = 0.8
Step 1: Error
Step 2: Loss
The network then propagates this error backward and updates its weights to reduce the loss in the next training iteration.
Flow of Backpropagation Error
Input│▼Hidden Layer│▼Output Layer│▼Calculate Error (Target − Output)│▼Compute Loss│▼Propagate Error Backward│▼Update Weights and Biases│▼Repeat Until Error is Minimized
Key Points
- Backpropagation error is the difference between the predicted and actual output, distributed backward through the network.
- It uses the chain rule from calculus to compute gradients efficiently.
- The calculated gradients are used to update weights and biases, helping the neural network learn and improve its predictions over multiple training iterations.
Examples of Using a Multilayer Perceptron (MLP)
A Multilayer Perceptron (MLP) is commonly used for tasks where the input is a fixed set of features and the goal is to predict a class or a numeric value.
1. Handwritten Digit Recognition
Problem: Recognize digits (0–9) written by hand.
- Input: Pixel values of a digit image (e.g., 28 × 28 = 784 pixels)
- Output: Digit (0–9)
Example:
Input Image → MLP → Output: 7
2. Spam Email Detection
Problem: Determine whether an email is spam.
- Input: Email features (keywords, sender, links, message length)
- Output: Spam or Not Spam
Example:
Email: "Congratulations! You won a prize." MLP Output → Spam
3. Student Pass/Fail Prediction
Problem: Predict whether a student will pass an exam.
Inputs:
- Study hours
- Attendance
- Assignment marks
Output:
- Pass
- Fail
Example:
| Study Hours | Attendance | Assignment Marks | Prediction |
|---|---|---|---|
| 7 | 90% | 85 | Pass |
| 2 | 60% | 45 | Fail |
4. House Price Prediction
Problem: Estimate the selling price of a house.
Inputs:
- Area
- Number of bedrooms
- Age of the house
- Location rating
Output:
- House price
Example:
Area = 1800 sq.ft Bedrooms = 3 Location Rating = 8 MLP Output → ₹75,00,000
5. Medical Diagnosis
Problem: Predict whether a patient has a disease.
Inputs:
- Age
- Blood pressure
- Blood sugar
- Cholesterol
Output:
- Disease Present
- Disease Absent
Example:
Patient Data → MLP → Diabetes Detected
6. Loan Approval Prediction
Problem: Decide whether a loan should be approved.
Inputs:
- Income
- Credit score
- Employment status
- Existing loans
Output:
- Approved
- Rejected
Example:
| Income | Credit Score | Prediction |
|---|---|---|
| ₹80,000 | 780 | Approved |
| ₹25,000 | 520 | Rejected |
7. Customer Churn Prediction
Problem: Predict whether a customer will leave a company.
Inputs:
- Monthly bill
- Contract type
- Customer support calls
- Years as a customer
Output:
- Stay
- Leave
Example:
Customer Data → MLP → Leave
8. Sentiment Analysis
Problem: Determine whether a review is positive or negative.
Input:
- Customer review text (converted into numerical features)
Output:
- Positive
- Negative
Example:
Review: "The product is excellent." MLP Output → Positive
Summary Table
| Application | Input | Output |
|---|---|---|
| Handwritten digit recognition | Image pixels | Digit (0–9) |
| Spam email detection | Email features | Spam / Not Spam |
| Student result prediction | Study hours, attendance | Pass / Fail |
| House price prediction | House features | Price |
| Medical diagnosis | Patient health data | Disease / No Disease |
| Loan approval | Financial information | Approved / Rejected |
| Customer churn prediction | Customer usage data | Stay / Leave |
| Sentiment analysis | Text features | Positive / Negative |
Key Point
An MLP works best when the data can be represented as a fixed set of numerical features. It is widely used for classification (e.g., spam detection, disease diagnosis, loan approval) and regression (e.g., house price prediction) tasks.
Derivation of Backpropagation (MLP)
Backpropagation is derived using the chain rule of calculus. It computes how the error changes with respect to each weight in the network, allowing the weights to be updated to reduce the error.
Step 1: Consider a Single Neuron
For one neuron:
where:
- = input
- = weight
- = bias
- = weighted sum
- = activation function
- = output
Step 2: Define the Error (Loss) Function
Using Mean Squared Error (MSE):
where:
- = target output
- = predicted output
The factor simplifies differentiation.
Step 3: Goal
We need to determine how the error changes with a weight :
Since depends on , depends on , and depends on , we use the chain rule.
Step 4: Apply the Chain Rule
Step 5: Compute Each Derivative
(a) Derivative of Error
Differentiate with respect to :
(b) Derivative of Activation Function
If the sigmoid activation is used:
Its derivative is:
(c) Derivative of Weighted Sum
Differentiate with respect to :
Step 6: Combine the Results
Substitute into the chain rule:
This is the gradient for a weight connected to the output neuron.
Step 7: Update the Weight
Using gradient descent:
Substitute the gradient:
where is the learning rate.
Hidden Layer Derivation
For a hidden neuron, the error is not directly known. It is computed from the errors in the next layer.
Let:
-
Hidden neuron output =
- Output neuron error term =
The hidden neuron error term is:
where:
- = weight from hidden neuron to output neuron
- = error term of output neuron
The weight update for a hidden-layer weight is:
Complete Backpropagation Algorithm
1. Initialize weights randomly. 2. Perform feedforward to compute the output. 3. Compute the loss. 4. Calculate output-layer error: δ = (y − t)f'(z) 5. Calculate hidden-layer errors: δh = f'(zh) Σ(wδ) 6. Update weights: w = w − ηδx 7. Repeat for all training examples until the error is minimized.
Flow Diagram
Input│▼Weighted Sum (z = wx + b)│▼Activation Function│▼Output (y)│▼Loss Function E│▼Compute Gradient using Chain Rule│▼Backpropagate Error│▼Update Weights
Key Formula Summary
| Step | Formula |
|---|---|
| Weighted sum | |
| Activation | |
| Loss | |
| Chain rule | |
| Output gradient (sigmoid + MSE) | |
| Weight update |
This derivation shows that backpropagation uses the chain rule to efficiently compute gradients for every weight in the network, enabling gradient descent to minimize the prediction error.
Support Vector Machine (SVM)
A Support Vector Machine (SVM) is a supervised machine learning algorithm used for classification and regression. It is mainly used for binary classification problems and works by finding the best separating boundary (hyperplane) between different classes.
Definition
An SVM finds the optimal hyperplane that separates data points of different classes while maximizing the margin between them.
Basic Idea
Consider two classes:
- Class A (●)
- Class B (▲)
An SVM tries to find a line (in 2D) or a hyperplane (in higher dimensions) that separates the two classes with the largest possible margin.
▲ ▲ ---------------------- ← Optimal Hyperplane ● ● ●
The larger the margin, the better the model is expected to generalize to new data.
Important Terms
1. Hyperplane
A hyperplane is the decision boundary that separates different classes.
- In 2D: a line
- In 3D: a plane
- In n dimensions: a hyperplane
Equation of a hyperplane:
where:
- = weight vector
- = input vector
- = bias
2. Support Vectors
Support vectors are the data points closest to the hyperplane.
They determine the position and orientation of the decision boundary.
▲ ▲ ▲ ---------------- ● ● ●
The nearest points (support vectors) are the most important points in training the SVM.
3. Margin
The margin is the distance between the hyperplane and the nearest data points from each class.
Support Vector ▲ | ------|---------------- Hyperplane | ● Support Vector
SVM aims to maximize this margin.
Mathematical Representation
The hyperplane is:
Classification rule:
Margin:
Maximizing the margin is equivalent to minimizing .
Types of SVM
1. Linear SVM
Used when the data are linearly separable.
▲ ▲ ▲ ----------- ● ● ●
2. Non-Linear SVM
Used when a straight line cannot separate the classes.
A kernel function maps the data into a higher-dimensional space where a linear separator may exist.
Kernel Functions
A kernel computes similarity between points without explicitly transforming them into higher dimensions.
Common kernels include:
1. Linear Kernel
Suitable for linearly separable data.
2. Polynomial Kernel
Captures polynomial relationships.
3. Radial Basis Function (RBF) Kernel
One of the most widely used kernels for nonlinear classification.
4. Sigmoid Kernel
Resembles the activation function used in neural networks.
Advantages of SVM
- Effective in high-dimensional feature spaces.
- Works well for both linear and nonlinear classification.
- Maximizes the margin, which often improves generalization.
- Uses only the support vectors, making the decision boundary compact.
- Can also be adapted for regression (Support Vector Regression, SVR).
Disadvantages of SVM
- Training can be slow for very large datasets.
- Choosing the right kernel and its parameters can be challenging.
- Less effective when classes overlap significantly or when the data contain substantial noise.
- Model interpretation is less intuitive than for simple linear models.
Applications
- Spam email detection
- Face recognition
- Handwritten digit recognition
- Text classification
- Medical diagnosis
- Image classification
- Bioinformatics (e.g., gene classification)
Example
Suppose we want to classify emails as Spam or Not Spam.
Input features:
- Number of links
- Number of suspicious words
- Sender reputation
The SVM learns the optimal decision boundary from labeled training data. When a new email is received, it determines on which side of the hyperplane the email lies and classifies it accordingly.
SVM Workflow
Training Data│▼Choose Kernel│▼Find Support Vectors│▼Construct Maximum-Margin Hyperplane│▼Train SVM Model│▼Predict Class for New Data
Summary
| Feature | SVM |
|---|---|
| Learning type | Supervised learning |
| Main purpose | Classification (also regression) |
| Decision boundary | Hyperplane |
| Key data points | Support vectors |
| Goal | Maximize the margin |
| Handles nonlinear data | Yes, using kernels |
| Common kernels | Linear, Polynomial, RBF, Sigmoid |
Key Point
A Support Vector Machine (SVM) is a powerful supervised learning algorithm that finds the maximum-margin hyperplane to separate classes. By relying on support vectors and kernel functions, SVMs can solve both linear and nonlinear classification problems effectively.
Learning with Trees: Decision Trees, Construction, CART
Decision Trees are supervised machine-learning algorithms used for both classification and regression. They make predictions by repeatedly splitting data according to feature values, forming a tree-like structure.
1. Learning with Trees
A decision tree consists of:
- Root node – starting point of the tree
- Internal/decision nodes – conditions based on features
- Branches – outcomes of those conditions
- Leaf nodes – final prediction
Example:
Weather / \ Sunny Rain / \ Humidity Wind / \ / \ High Normal Weak Strong | | | | No Yes Yes No
Here, the tree predicts whether a person will play tennis based on weather conditions.
Why use decision trees?
- Easy to understand and interpret
- Can handle numerical and categorical features
- Requires relatively little data preprocessing
- Can model nonlinear relationships
- Useful for both classification and regression
2. Decision Trees
A decision tree learns a sequence of if–then rules from training data.
For example:
IF income > ₹50,000 IF age > 30 → Loan Approved ELSE → Loan Rejected ELSE → Loan Rejected
The algorithm tries to choose splits that make the resulting groups as pure as possible.
Classification tree
The target is a category.
Examples:
- Spam / Not Spam
- Disease / No Disease
- Pass / Fail
- Fraud / Not Fraud
Regression tree
The target is a numerical value.
Examples:
- House price
- Sales
- Temperature
- Revenue
3. Constructing Decision Trees
The general process is:
Training Data ↓ Select the best feature/split ↓ Split the data ↓ Create child nodes ↓ Repeat recursively ↓ Stopping condition ↓ Leaf prediction
The important question is:
How do we choose the best split?
Different decision-tree algorithms use different criteria.
3.1 Entropy
Entropy measures the impurity or uncertainty in a dataset.
For a binary classification problem:
where and are the proportions of the two classes.
Example
Suppose a node contains:
- 5 Yes
- 5 No
Then:
Therefore:
This represents maximum uncertainty for a binary node.
If all observations belong to one class:
So:
| Node composition | Entropy |
|---|---|
| 10 Yes, 0 No | 0 |
| 8 Yes, 2 No | 0.722 |
| 5 Yes, 5 No | 1 |
| 2 Yes, 8 No | 0.722 |
| 0 Yes, 10 No | 0 |
4. Information Gain
Information Gain measures how much a split reduces uncertainty.
The feature with the largest information gain is selected as the split.
Simple example
Suppose:
Before split: Entropy = 1.0 After splitting: Weighted entropy = 0.4
Then:
A larger information gain indicates a stronger reduction in impurity.
5. Gini Impurity
Another popular splitting criterion is Gini impurity.
For binary classification:
For 50% Yes and 50% No:
For a completely pure node:
Lower Gini impurity is better.
6. Classification and Regression Trees — CART
CART stands for:
Classification and Regression Trees
It is a popular decision-tree methodology used for both classification and regression.
CART generally creates binary splits.
Feature X < 50? / \ Yes No / \ Node 1 Node 2
Unlike some tree algorithms that can create multiple branches from a categorical feature, CART typically divides a node into two child nodes.
6.1 CART Classification
For classification, CART commonly uses Gini impurity to select splits.
The algorithm searches for a split that minimizes the weighted impurity of the resulting child nodes.
Conceptually:
where:
- = number of samples in left node
- = number of samples in right node
- = total samples
- = impurity of the child nodes
The split producing the lowest weighted impurity is selected.
7. CART Regression
For regression, the target variable is continuous.
Example:
Area < 1500? / \ Yes No / \ Price prediction Price prediction
CART regression commonly chooses splits that minimize squared error.
A leaf prediction is usually the mean target value of the training observations reaching that leaf.
For example:
Leaf contains: ₹40 lakh ₹45 lakh ₹50 lakh
Prediction:
So the regression tree predicts:
₹45 lakh
8. Least-Squares Regression
Regression trees are closely related to minimizing squared prediction error within leaves.
For a leaf , the prediction can be written as:
The objective is to minimize:
9. Stopping Criteria
A tree can continue splitting until every leaf contains only a few observations. This can cause overfitting.
Common stopping conditions include:
- Maximum tree depth reached
- Minimum number of samples required for splitting
- Minimum number of samples in a leaf
- No useful improvement from a split
- Maximum number of leaf nodes reached
For example:
DecisionTreeClassifier( max_depth=5, min_samples_split=10, min_samples_leaf=5 )
10. Overfitting and Pruning
A very deep tree may memorize the training data.
Small tree Very deep tree X X / \ / \ X X X X / \ / \ / \ / \ ... ... ... ... ...
Overfitting
Training accuracy: 99% Testing accuracy: 72%
The model has learned the training data too specifically.
Pruning
Pruning removes unnecessary branches to improve generalization.
Two approaches are:
Pre-pruning
Stop tree growth early using parameters such as:
-
max_depth -
min_samples_split -
min_samples_leaf
Post-pruning
First grow a larger tree and then remove branches that provide insufficient benefit.
11. Decision Tree Algorithm — Summary
Training Dataset ↓ Calculate impurity ↓ Evaluate possible splits ↓ Select best split ↓ Split dataset / \ / \ Child node Child node ↓ ↓ Repeat recursively ↓ Stopping rule ↓ Leaf prediction
Classification
Input → Decision Tree → Class ↓ Gini / Entropy
Regression
Input → Decision Tree → Numerical value ↓ Squared Error
12. Classification vs Regression Trees
| Feature | Classification Tree | Regression Tree |
|---|---|---|
| Target | Categorical | Numerical |
| Example | Spam/Not Spam | House price |
| Common CART criterion | Gini impurity | Squared error |
| Leaf prediction | Class / class probability | Mean value |
| Output | Category | Number |
| Evaluation | Accuracy, Precision, Recall, F1 | MAE, MSE, RMSE, R² |
13. Advantages
Decision trees:
- Easy to interpret
- Easy to visualize
- Handle nonlinear relationships
- Can handle categorical and numerical variables
- Do not require feature scaling
- Can be used for classification and regression
14. Limitations
- Can overfit easily
- Small changes in data can produce a different tree
- Individual trees may have lower predictive performance than ensemble methods
- Deep trees can become difficult to interpret
- Greedy split selection does not necessarily produce a globally optimal tree
Exam-Oriented Quick Revision
Decision Tree: A supervised learning model that recursively divides data using feature-based rules.
Entropy: Measures uncertainty/impurity.
Information Gain: Reduction in entropy after a split.
Gini Impurity:
CART: Classification and Regression Trees; commonly uses binary splits.
Classification Tree: Predicts discrete classes.
Regression Tree: Predicts continuous numerical values.
Pruning: Removes unnecessary tree branches to reduce overfitting.
No comments:
Post a Comment