1. What is Machine Learning? (ML)
Machine Learning is a modern technology that helps computers learn from data. This means a computer looks at many examples and slowly understands patterns on its own.
Why is ML important?
Because now:
- Computers can recognize faces
- Cars can drive automatically
- Websites can recommend videos you like
- Apps can translate languages instantly
Simple understanding
ML is like training a student:
- Show many math problems → student learns pattern
- Show many pictures → student learns differences
The more examples you give, the smarter the computer becomes.
Python Example (Simple ML Prediction)
from sklearn.neighbors import KNeighborsClassifier
X = [[1], [2], [3], [4], [5]] # hours studied
y = [0, 0, 1, 1, 1] # 0 = fail, 1 = pass
model = KNeighborsClassifier(n_neighbors=3)
model.fit(X, y)
print(model.predict([[3]]))2. What is Artificial Intelligence (AI)?
Artificial Intelligence is a field in computer science that tries to make machines act like humans.
AI can:
- Think
- Learn
- Plan
- Speak
- Understand images
- Make decisions
Simple example
AI is used when:
- Google Maps finds the fastest route
- Siri answers your questions
- Your camera detects your face
ML is a part of AI.
Python Example (Simple Rule-Based AI)
def smart_home(temp):
if temp > 30:
return "Turn ON AC"
else:
return "Temperature is OK"
print(smart_home(31))3. ML vs AI vs Deep Learning
| Concept | Meaning | Easy Example |
|---|---|---|
| AI | Smart machines | Self-driving car |
| ML | Learning from data | Car learns road signs |
| DL | ML + neural networks | Car detects people |
Deep Learning
Deep Learning uses "neurons" like the human brain. This helps computers:
- Detect faces
- Translate languages
- Understand speech
4. Types of Machine Learning
A. Supervised Learning
Computer learns from labeled data.
Example:
| Image | Label |
|---|---|
| 🍎 | "apple" |
| 🐶 | "dog" |
Computer learns the relationship.
Python Example
from sklearn.neighbors import KNeighborsClassifier
X = [[1],[2],[3],[4]]
y = [0,0,1,1]
model = KNeighborsClassifier()
model.fit(X, y)
print(model.predict([[3]]))B. Unsupervised Learning
Computer learns without labels. It tries to group similar things together.
Simple example:
- Group customers
- Detect unusual activity in bank accounts
Python Example
from sklearn.cluster import KMeans
X = [[1], [2], [8], [9]]
kmeans = KMeans(n_clusters=2, n_init=10)
kmeans.fit(X)
print(kmeans.labels_)C. Reinforcement Learning
Computer learns by trial and error and receives rewards.
Example:
- Robot learning to walk
- Game AI learning to win
Python Example
reward = 0
actions = ["left", "right"]
for step in range(6):
action = actions[step % 2]
if action == "right":
reward += 1
print("Action:", action, "Reward:", reward)5. Python Basics for ML (VS Code Setup)
- Step 1 — Install Python
From: https://python.org - Step 2 — Install VS Code
From: https://code.visualstudio.com - Step 3 — Install Python Extension
Search "Python" → Install - Step 4 — Create a Virtual Environment
python -m venv venv - Step 5 — Activate
Windows:venv\Scripts\activate - Step 6 — Install ML Libraries
pip install numpy pandas matplotlib scikit-learn
6. NumPy Basics
NumPy helps with:
- Arrays
- Math
- Fast calculations
Python Example
import numpy as np
arr = np.array([10, 20, 30])
print("Mean:", arr.mean())
print("Max:", arr.max())7. Pandas Basics
Pandas is used for table-like data.
Python Example
import pandas as pd
df = pd.DataFrame({
"name": ["Ali", "Sara"],
"age": [15, 16]
})
print(df)8. Data Cleaning & Visualization
Cleaning data
import pandas as pd
df = pd.read_csv("students.csv")
df = df.dropna()
print(df.head())Visualizing Data
import matplotlib.pyplot as plt
plt.plot([1,2,3],[2,4,6])
plt.title("Study Hours vs Marks")
plt.show()9. First ML Model — Linear Regression
Linear Regression predicts numbers.
Python Example
import numpy as np
from sklearn.linear_model import LinearRegression
X = np.array([[1],[2],[3],[4]])
y = np.array([50, 60, 70, 80])
model = LinearRegression()
model.fit(X, y)
print("Prediction for 5 hours:", model.predict([[5]]))