Minu's Games logo
MINU'S ROBOTICS

A Minu's Games EdTech Lab

← Code & Cognition
Day 24 of 30Artificial Intelligence

🌸Your First ML Model — Classification

🎯 Today's objective

Train a classifier with scikit-learn.

📖 Key concepts

  • Classification predicts a category
  • fit() learns, predict() guesses
  • train_test_split
  • accuracy_score evaluates

💻 Try this code

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import accuracy_score

X, y = load_iris(return_X_y=True)
Xtr, Xte, ytr, yte = train_test_split(X, y, test_size=0.2)
m = KNeighborsClassifier().fit(Xtr, ytr)
print("accuracy:", accuracy_score(yte, m.predict(Xte)))

👥 Learn it your way

🧒 Young Explorers

You just trained a real AI that tells flower species apart — in ~8 lines!

Your task

Run the iris example; change test_size and watch accuracy move.

💼 Professionals

Understand the fit/predict API, baseline accuracy, and why KNN is a sane first try.

Your task

Swap KNN for DecisionTreeClassifier; compare accuracy and comment.

🤖 AI connection

This fit→predict→evaluate loop is identical whether you classify flowers, spam, or tumours — it scales straight up to industry ML.

✅ Quick check

What does .fit() do?

Trains the model on the training data.

What does classification predict?

A category/class label.