7.1.1 What is Machine Learning?
Machine Learning (ML) is a branch of Artificial Intelligence (AI) that enables computers to learn patterns from data and make predictions or decisions without being explicitly programmed for every possible situation.
In traditional programming, we provide:
Rules + Data → Output
In machine learning, we provide:
Data + Expected Output → Learning Algorithm → Model
The trained model can then be used to make predictions on new, unseen data.
Simple Example
Suppose we want to predict whether an email is spam or not spam.
A traditional program might contain thousands of manually written rules:
IF email contains "free money"
THEN spam
IF email contains "winner"
THEN spam
...
A machine learning system can instead learn from historical emails:
Training Data
↓ Emails + Labels ↓ ML Algorithm ↓ Trained Model ↓ New Email ↓ Spam / Not Spam
The important idea is that the model learns relationships and patterns from examples.
7.1.2 Why Do We Need Machine Learning?
- Traditional programming works well when rules can be clearly defined.
- For example:
- IF age >= 18
THEN eligible = True
ELSE
eligible = False
However, many real-world problems are difficult to solve using fixed rules.
Examples include:
Detecting fraudulent transactions
Recognizing faces
Predicting customer churn
Recommending movies
Predicting house prices
Detecting spam
Predicting equipment failures
Understanding natural language
Identifying diseases from medical images
Forecasting sales
For these problems, manually writing rules for every possible scenario is impractical.
Machine learning allows the computer to discover useful patterns from historical data.
7.1.3 Traditional Programming vs Machine Learning
| Traditional Programming | Machine Learning |
|---|---|
| Rules are explicitly written | Rules/patterns are learned from data |
| Programmer defines logic | Algorithm learns relationships |
| Data + Rules → Output | Data + Output → Model |
| Usually deterministic | Often probabilistic |
| Changes require modifying rules | Model can be retrained with new data |
| Suitable for well-defined rules | Suitable for complex patterns |
Example: House Price Prediction
Traditional programming would require rules such as:
IF area > 2000 AND location = A
- price = ...
- This becomes complicated because house prices depend on many factors.
- Machine learning can learn the relationship:
- Area
- Bedrooms
- Location
- Age
- Parking
- Distance from city
↓ Machine Learning Model ↓ Predicted Price
7.1.4 Artificial Intelligence vs Machine Learning vs Deep Learning
These three terms are closely related but are not identical.
Artificial Intelligence (AI)
│ ├── Machine Learning (ML) │ │ │ ├── Traditional ML │ │ ├── Linear Regression │ │ ├── Decision Trees │ │ ├── SVM │ │ └── K-Means │ │ │ └── Deep Learning │ ├── Neural Networks │ ├── CNN │ ├── RNN │ └── Transformers Artificial Intelligence
AI is the broader field concerned with building systems capable of performing tasks that normally require human intelligence.
Examples:
Reasoning
Planning
Perception
Language understanding
Decision-making
Machine Learning
ML is a subset of AI where systems learn from data.
Deep Learning
Deep Learning is a subset of ML based primarily on multi-layer neural networks.
7.1.5 How Machine Learning Works
A typical ML system follows these steps:
Data
↓ Data Preprocessing ↓ Feature Engineering ↓ Training Dataset ↓ ML Algorithm ↓ Trained Model ↓ Model Evaluation ↓ Model Deployment ↓ Predictions on New Data
For example, suppose a company wants to predict whether a customer will leave.
The dataset might contain:
| Customer | Age | Tenure | Monthly Charges | Support Calls | Churn |
|---|---|---|---|---|---|
| C001 | 25 | 2 | 850 | 5 | Yes |
| C002 | 42 | 8 | 450 | 1 | No |
| C003 | 31 | 3 | 700 | 4 | Yes |
| C004 | 51 | 10 | 400 | 0 | No |
- The algorithm learns patterns between customer characteristics and churn.
- For a new customer:
- Age = 29
- Tenure = 2
- Monthly Charges = 800
- Support Calls = 5
- the model may predict:
- Churn Probability = 87%
7.1.6 Important Terminology
Understanding ML terminology is essential.
Dataset
A collection of data used for machine learning.
Example:
customer_data.csv
Feature
An input variable used by the model.- For customer churn:
- Age
- Tenure
- Monthly Charges
- Support Calls
- are features.
Target
The variable that the model attempts to predict.
Example:
Churn
Observation / Sample
- One individual record in the dataset.
- C001 | 25 | 2 | 850 | 5 | Yes
- is one sample.
Model
A mathematical representation learned from data.
Examples:
Linear Regression model
Decision Tree model
Random Forest model
Logistic Regression model
Training
The process of allowing an algorithm to learn patterns from historical data.
Prediction
The output generated by a trained model for new data.
7.1.7 Features and Target
Consider a dataset for predicting employee salary:
| Experience | Education | Location | Age | Salary |
|---|---|---|---|---|
| 2 | Bachelor's | Hyderabad | 25 | 600000 |
| 5 | Master's | Bengaluru | 30 | 1000000 |
| 8 | Master's | Hyderabad | 35 | 1500000 |
- Here:
- Features:
- Experience
- Education
- Location
- Age
- Target:
- Salary
- The model learns:
\[X \rightarrow Y\]
where:
(X) = input features
(Y) = target/output
7.1.8 Types of Machine Learning
Machine learning is commonly divided into three major categories:
1. Supervised Learning
The training data contains the correct answers.
Input Data + Known Output
↓ Algorithm ↓ Model
Examples:
House price prediction
Spam detection
Customer churn prediction
Disease classification
Two major supervised learning tasks are:
Regression
Predict a continuous numerical value.
Example:
- House Price = ₹85,00,000
- Classification
- Predict a category.
Example:
Spam = Yes
2. Unsupervised Learning
- The training data does not contain predefined answers.
- The algorithm attempts to discover hidden patterns or structures.
- Input Data
↓ ML Algorithm ↓ Patterns / Groups
Examples:
Customer segmentation
Document clustering
Anomaly detection
Dimensionality reduction
Common algorithms include:
K-Means
Hierarchical Clustering
PCA
3. Reinforcement Learning
- An agent learns by interacting with an environment.
- The agent receives rewards or penalties based on its actions.
- Environment
↑ │ Action │ Agent │ Reward ↓
Examples:
Game-playing AI
Robotics
Autonomous systems
Resource optimization
7.1.9 Training, Validation and Test Data
A dataset is commonly divided into multiple parts.
Training Set
Used to train the model.Typical proportion:
70–80%
Validation Set
- Used to tune the model and compare alternatives.
- Typical proportion:
- 10–15%
Test Set
- Used for the final unbiased evaluation.
- Typical proportion:
- 10–20%
- A common workflow is:
- Complete Dataset
│ ┌─────────┴─────────┐ ↓ ↓ Training Test │ ↓ Validation
The exact split depends on the problem and dataset size.
7.1.10 What Does a Machine Learning Model Learn?
A model generally learns parameters that describe relationships between input variables and the target.
For example, linear regression may learn:
\[y = b_0 + b_1x\]
where:
(x) = input
(y) = prediction
(b_0) = intercept
(b_1) = learned coefficient
Suppose:
\[Salary = 500000 + 150000 \times Experience\]
For 5 years of experience:
\[Salary = 500000 + (150000 \times 5)\]
\[Salary = 1,250,000\]
The coefficients were learned from training data.
7.1.11 Machine Learning Example Using Python
A simple example using Scikit-learn:
from sklearn.linear_model import LinearRegression
X = [[1], [2], [3], [4], [5]]
y = [30000, 40000, 50000, 60000, 70000]
model = LinearRegression()
model.fit(X, y)
prediction = model.predict([[6]])
print(prediction)The important operation is:
model.fit(X, y)fit() trains the model using the supplied examples.
Then:
model.predict([[6]])asks the trained model to make a prediction for a new input.
7.1.12 Applications of Machine Learning
Machine learning is used across almost every industry.
Finance
Fraud detection
Credit scoring
Risk analysis
Algorithmic trading
Healthcare
Disease prediction
Medical image analysis
Drug discovery
Patient risk prediction
Retail
Recommendation systems
Customer segmentation
Demand forecasting
Dynamic pricing
Manufacturing
Predictive maintenance
Quality inspection
Production optimization
Banking
Loan approval
Fraud detection
Customer churn prediction
Transportation
Route optimization
Traffic prediction
Autonomous driving
Technology
Search engines
Voice assistants
Recommendation systems
Generative AI
7.1.13 Advantages of Machine Learning
1. Automation
ML can automate complex decision-making tasks.
2. Pattern Detection
It can identify patterns that may be difficult for humans to detect.
3. Scalability
Models can process very large datasets.
4. Adaptability
Models can be retrained as new data becomes available.
5. Prediction
ML can predict future outcomes based on historical patterns.
7.1.14 Limitations of Machine Learning
Machine learning is not automatically intelligent or correct.
1. Requires Quality Data
Poor data can produce poor models.
This is often summarized as:
Garbage In → Garbage Out
2. Bias
If training data contains bias, the model can learn that bias.
3. Overfitting
A model can memorize training data instead of learning general patterns.
4. Computational Cost
Some ML algorithms require significant computing resources.
5. Interpretability
Some complex models can be difficult to explain.
6. Data Dependency
A model's performance can degrade when real-world data changes significantly from its training data.
7.1.15 Machine Learning Lifecycle
A real-world ML project usually follows this lifecycle:
13. Retrain When Required
This lifecycle is important because building the model is only one part of an ML project.
7.1.16 Key Takeaways
Machine Learning is a subset of Artificial Intelligence.
ML systems learn patterns from data.
Features are inputs used by a model.
Target is the value the model attempts to predict.
Supervised learning uses labeled data.
Unsupervised learning discovers patterns without labeled outputs.
Reinforcement learning learns through rewards and penalties.
Regression predicts numerical values.
Classification predicts categories.
Training data is used to learn the model.
Validation data helps tune the model.
Test data is used for final evaluation.
Good-quality data is critical to successful ML.
ML does not eliminate the need for domain knowledge.
A production ML system requires deployment and monitoring in addition to model training.
Quick Revision
AI → Broad field of intelligent systems ML → Systems learn from data Deep Learning → ML using deep neural networks Feature → Input variable Target → Output to predict Training → Learning from data Prediction → Applying learned model to new data Regression → Predict a number Classification → Predict a category Clustering → Discover groups Model Evaluation → Measure model performance