๐ How Machine Learning Works
Not magic. Maths + patterns + data.
1๏ธโฃ
Step 1: Collect Data โ Get 100 emails. Label each: SPAM or NOT SPAM. More data = smarter AI.
2๏ธโฃ
Step 2: Extract Features โ Turn text into NUMBERS. Count exclamation marks, "FREE", links, ALL CAPS. Each = a feature.
3๏ธโฃ
Step 3: Find Patterns โ Algorithm finds rules: "3+ exclamations AND 'FREE' = spam 95% of the time." Decision tree.
4๏ธโฃ
Step 4: Test It โ Give it UNSEEN emails. Correct answers = accuracy. 90% = 9 out of 10 right.
5๏ธโฃ
Step 5: Improve โ Add data, add features, try algorithms. 85% โ 92% โ 97%. That's learning.
๐ The Actual Code (10 lines!)
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
# Load data
X = [[3,1,1,0], [0,0,0,1], ...]
y = ["spam", "ok", ...]
# Train
model = DecisionTreeClassifier()
model.fit(X_train, y_train)
# Predict
model.predict([[5,1,1,0]]) # โ "spam"
๐ก
10 lines. That's all. The student imports scikit-learn, trains a model, and predicts. The library does the maths โ the student understands the LOGIC.