Definition of Machine Learning (ML)
Machine Learning (ML) is a subset of Artificial Intelligence (AI) that focuses on developing systems that
can learn and make decisions or predictions from data without being explicitly programmed. It involves
designing algorithms that can automatically improve with experience.
Types of Machine Learning
1. Supervised Learning
o Definition: The model learns from labeled data, where the input-output relationship is
known.
o Theoretical Example: Predicting house prices based on features like size, location, and
number of rooms.
o Programming Example: Training a regression model in Python using sklearn:
python
Copy code
from sklearn.linear_model import LinearRegression
X = [[1400], [1600], [1700]] # Feature: House size (sq ft)
y = [300000, 350000, 400000] # Label: House prices
model = LinearRegression()
model.fit(X, y)
prediction = model.predict([[1500]])
print(prediction) # Predicted price
2. Unsupervised Learning
o Definition: The model identifies patterns or structures in unlabeled data.
o Theoretical Example: Grouping customers based on purchasing behavior for targeted
marketing.
o Programming Example: Using K-means clustering in Python:
python
Copy code
from sklearn.cluster import KMeans
import numpy as np
data = np.array([[1, 2], [1, 4], [1, 0], [10, 2], [10, 4], [10, 0]])
kmeans = KMeans(n_clusters=2, random_state=0)
kmeans.fit(data)
print(kmeans.labels_) # Cluster assignments
3. Reinforcement Learning
o Definition: The model learns by interacting with an environment and receiving rewards
or penalties.
o Theoretical Example: A robot learning to walk by trial and error.
o Programming Example: Using gym to simulate a reinforcement learning environment:
python
Copy code
import gym
env = gym.make('CartPole-v1')
state = env.reset()
for _ in range(1000):
env.render()
action = env.action_space.sample() # Random action
next_state, reward, done, _ = env.step(action)
if done:
break
env.close()
Summary Table
Type Key Focus Data Requirement Example Task
Supervised Learning Predict outcomes Labeled data Email spam classification
Unsupervised Learning Find patterns or structure Unlabeled data Customer segmentation
Reinforcement Learning Learn from environment Rewards and penalties Autonomous car driving
This combination of theory and programming ensures that students grasp both the conceptual and
practical aspects of ML.