Title: Lab 11 — Classifying Iris Flowers with scikit-learn
Course: AIINFRA 100: AI Systems & Development Environments > Section: Week 11 — Machine Learning Libraries: scikit-learn

🛠️ Lab 11 — Classifying Iris Flowers with scikit-learn (50 pts)

Goal: Use scikit-learn's Estimator API to train a classifier on the classic Iris dataset, evaluate it correctly with a held-out test set, and see overfitting and cross-validation in action — all for free in Google Colab. Steps:

1. Open a new notebook at Google Colab (no installation needed — scikit-learn is already available).
2. In the first cell, import what you'll need:

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

1. Load the built-in Iris dataset with load_iris(). Print X.shape and the target names to confirm you have 150 samples across 3 flower species.
2. Split the data into training and test sets with train_test_split(X, y, test_size=0.2, random_state=42) (an 80/20 split).
3. Create a KNeighborsClassifier() and fit it on the training data with .fit(X_train, y_train).
4. Use .predict(X_test) to generate predictions, then print the test accuracy with accuracy_score(y_test, y_pred).
5. Print a confusion matrix with confusion_matrix(y_test, y_pred) and write one sentence in a markdown cell explaining what it shows.
6. To see overfitting for yourself: also score the model on the training data (model.predict(X_train) vs. y_train) and compare that accuracy to your test accuracy. Note whether they are close or far apart.
7. Stretch goal (optional, for extra credit): Wrap a scaler and your classifier in a Pipeline, then run cross_val_score(pipeline, X, y, cv=5) and compare the average cross-validated score to your original single-split test accuracy.
8. Add short markdown notes above each code cell explaining what it does, in your own words.

Deliverables: Submit your Colab notebook link (with sharing turned on) or a downloaded .ipynb/PDF export showing your code, output (accuracy score, confusion matrix), and your written observations about train-vs-test accuracy.