Build an AI Flower Classifier
Train and evaluate an Iris flower classifier in Google Colab.
Introduction
30 Second Summary
Flowers can look alike at first glance, especially when their differences come down to a few small measurements. A consistent way to compare those measurements can reveal patterns that your eyes miss.
In this project, you will build a flower classifier in Google Colab with Python. You will take Iris measurements through a complete machine learning workflow from visual patterns to an evaluated species prediction.
What You'll Build
Your finished notebook ends with a visible species prediction grounded in the flower groups displayed above it.
By the end of this project, you'll have:
- A data walkthrough that moves from five labeled samples to a color-coded scatter plot of all three Iris species.
- An honest evaluation where a deliberately weak baseline establishes the performance floor. A held-out accuracy score shows whether the trained classifier beats it. A labeled confusion matrix reveals which predictions were correct.
- An editable prediction demo that turns four measurements into one of the three Iris species names.
- Secret Mission: Find one misclassified test flower. Explain the confusion from its measurements. Connect your explanation to the scatter plot.
Do I need any experience before starting?
You need a Google account plus a modern web browser. No previous Python or machine learning experience is required.
Before We Start
Before the hands-on work begins, commit to the notebook you are building. A clear purpose gives every later code cell a reason to exist.
Set Up Your Colab Notebook
Your classifier needs a stable software environment so every later result can be reproduced.
Google Colab provides a hosted notebook in your browser. Its managed runtime removes local setup from this project.
The selected runtime fixes the Python version. Pinned installs fix the scikit-learn and Matplotlib versions.
In this step, get ready to:
- Create a named Google Colab notebook.
- Select the pinned managed runtime.
- Verify the environment with the Iris dataset shape.
Create your named notebook
Colab notebooks are stored in Google Drive. A clear filename makes this project easy to find later.
The notebook never needs your Google password.
- Go to Google Colab in your browser.
- Complete the Google account sign-in flow if Colab requests it.
- Confirm your Google account avatar is visible on the Colab page.
- Select the option for creating a blank notebook.
- Select the current notebook title in the top-left corner.
- Replace the current title with flower_classifier.ipynb.
- Press Enter to apply the filename.
You'll see flower_classifier.ipynb in the top-left title area.
That is the first milestone complete: your notebook now has a shareable home in Google Drive.
Pin the managed runtime
A Colab Runtime Version identifies the managed software environment behind your notebook. Runtime 2026.07 includes Python 3.12.13.
Past runtime connections can take 2 to 3 minutes. A quiet connection indicator during this wait is expected.
- Open the Runtime menu at the top of the notebook.
- Select Change runtime type.
- Open the Runtime Version dropdown.
- Select 2026.07.
- Confirm the selected runtime using the dialog's confirmation control.
- Wait until the notebook reconnects to its managed runtime.
The notebook is now connected to Runtime Version 2026.07. This gives your notebook Python 3.12.13.
That setup uncertainty is gone: your notebook now starts from the required Python environment.
Prepare the pinned environment
Pinned package versions keep library behavior consistent across future notebook runs. Cell 1 installs the exact versions used throughout this project.
- Install the pinned packages in the notebook's first code cell by pasting this command:
!pip install scikit-learn==1.9.1 matplotlib==3.11.2
What does this command do?
- The !pip install prefix runs the package installer inside the managed notebook runtime.
- The == pins scikit-learn to 1.9.1.
- The second pin installs Matplotlib 3.11.2.
- Run Cell 1 using the play control beside the cell.
- Wait until Cell 1 finishes running.
You'll see the cell's running indicator stop after the package installation completes.
Package cell not finishing?
- Reconnect the managed runtime if the cell cannot start.
- Rerun Cell 1 after the connection returns.
- Use help me diagnose why my pinned package installation is not completing in Google Colab if the installation still fails.
Before you run the environment check, what shape do you expect from a dataset containing 150 flowers with four measurements each?
- Add a temporary code cell below Cell 1 by pasting this verification line:
from sklearn.datasets import load_iris; print(load_iris().data.shape)
What does this check do?
- The load_iris() function loads the built-in Iris classification dataset.
- The .data.shape value reports the number of sample rows and feature columns.
- Run the temporary verification cell using its play control.
You'll see (150, 4) beneath the cell.
That shape is your proof: scikit-learn loaded all 150 rows with four feature columns.
Shape output missing?
- Confirm Cell 1 finished before running the temporary verification cell.
- Confirm the notebook is connected to the managed runtime.
- Use help me fix my Iris dataset shape check in Google Colab if the output still does not appear.
This deletion removes only the temporary check while keeping the reusable package cell intact.
- Remove the temporary verification cell using its cell toolbar.
- Confirm the notebook now contains only Cell 1.
✔️ Awesome, I've got everything!
Your notebook contains the pinned installation cell required for the next step.
ⓧ I'd like to double check the full code
!pip install scikit-learn==1.9.1 matplotlib==3.11.2
What should this notebook contain?
This reference is the complete notebook code for this step. It contains Cell 1 with both pinned package versions.
Your reproducible Colab environment is ready. Next, you'll load the flower measurements and turn them into your first visual result.
Visualize the Iris Flowers
The shape check in your configured Google Colab notebook proved the Iris dataset is available. Its 150 rows still look like numbers instead of flowers.
Each row pairs four features with one species label. A scatter plot turns two petal features into visible groups before any classifier appears.
In this step, get ready to:
- Import the APIs required by the notebook.
- Inspect five labeled Iris samples.
- Plot petal length against petal width for each species.
Import the notebook tools
Matplotlib provides the charting interface. scikit-learn provides the dataset plus the machine learning APIs used throughout the notebook.
- Select the add-code control beneath Cell 1.
You see a new empty code cell directly beneath the package installation cell.
- Paste these imports into Cell 2:
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import ConfusionMatrixDisplay, accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
What Do These Imports Prepare?
- The plt alias gives the plotting cell a short reference to Matplotlib.
- The load_iris function provides the built-in flower dataset.
- The remaining imports prepare the machine learning APIs required by the complete notebook workflow.
- Run Cell 2 using the play icon on its left.
Cell 2 completes without an error. Your notebook can now access every imported API.
Import Cell Not Completing?
- Rerun Cell 1 if an imported package is unavailable.
- Compare each line in Cell 2 with the import block above.
- Get help with the import that still fails.
Inspect the Iris dataset
The X matrix stores one measurement row for each flower. The y array stores the matching species index for each row.
- Add Cell 3 directly beneath Cell 2.
- Paste the dataset inspection code into Cell 3:
iris = load_iris()
X = iris.data
y = iris.target
print("Sample count:", X.shape[0])
print("Feature names:", iris.feature_names)
print("Species names:", iris.target_names)
print("First five labeled samples:")
for measurements, species_index in zip(X[:5], y[:5]):
named_measurements = dict(zip(iris.feature_names, measurements))
print(named_measurements, "->", iris.target_names[species_index])
What Does This Inspection Do?
- The load_iris() call loads the measurements plus their descriptive names.
- The X matrix holds 150 rows with four measurements per row.
- The y array holds one matching species index per row.
- The loop converts the first five rows into dictionaries with readable feature names.
- Run Cell 3 using the play icon on its left.
You see a sample count of 150. You also see four feature names plus three species names.
Under First five labeled samples: you see five measurement dictionaries. Each line ends with its matching species name.
Good progress. Your notebook now presents the first raw rows as labeled flower examples.
Dataset Details Not Appearing?
- Run Cell 2 again if Cell 3 reports that an imported name is unavailable.
- Confirm that Cell 3 contains the complete loop from the code above.
- Get help with dataset output that differs from the expected result.
Plot the flower groups
Petal length becomes the horizontal axis. Petal width becomes the vertical axis.
- Add Cell 4 directly beneath Cell 3.
- Paste the labeled scatter plot code into Cell 4:
figure, ax = plt.subplots()
for class_index, class_name in enumerate(iris.target_names):
ax.scatter(
X[y == class_index, 2],
X[y == class_index, 3],
label=class_name,
alpha=0.7,
)
ax.set_xlabel(iris.feature_names[2])
ax.set_ylabel(iris.feature_names[3])
figure.suptitle("Iris Flower Measurements")
ax.legend()
plt.show()
How Does the Plot Separate Species?
- The plt.subplots() call creates the figure plus the axes that hold the chart.
- The loop filters X for one species during each pass.
- Each ax.scatter() call draws one labeled group with partial transparency.
- The final lines label both axes. They also add the chart title plus the species legend.
Before you run Cell 4, which species group do you expect to look most separate from the others?
- Run Cell 4 using the play icon on its left.
You see a chart titled Iris Flower Measurements. Its axes show petal length plus petal width.
Three color-coded groups appear with a species legend. Your notebook has turned the measurements into a visible pattern.
Plot Missing or Incomplete?
- Run Cell 3 again if Cell 4 cannot find iris.
- Confirm that the two scatter coordinates use feature positions 2 plus 3.
- Confirm that ax.legend() appears before plt.show().
- Get help with a scatter plot that still looks different.
- Use the comparison tabs to check the complete notebook at this stage.
✔️ Awesome, I've got everything!
Excellent. Cells 1 through 4 are complete in flower_classifier.ipynb.
ⓧ I'd like to double check the full code
!pip install scikit-learn==1.9.1 matplotlib==3.11.2
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import ConfusionMatrixDisplay, accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
iris = load_iris()
X = iris.data
y = iris.target
print("Sample count:", X.shape[0])
print("Feature names:", iris.feature_names)
print("Species names:", iris.target_names)
print("First five labeled samples:")
for measurements, species_index in zip(X[:5], y[:5]):
named_measurements = dict(zip(iris.feature_names, measurements))
print(named_measurements, "->", iris.target_names[species_index])
figure, ax = plt.subplots()
for class_index, class_name in enumerate(iris.target_names):
ax.scatter(
X[y == class_index, 2],
X[y == class_index, 3],
label=class_name,
alpha=0.7,
)
ax.set_xlabel(iris.feature_names[2])
ax.set_ylabel(iris.feature_names[3])
figure.suptitle("Iris Flower Measurements")
ax.legend()
plt.show()
Your notebook now turns flower measurements into a labeled chart. Next, you will test a baseline that ignores those measurements.
Test a Baseline Classifier
Your scatter plot in Google Colab made the three flower species visible. A picture alone cannot tell you whether a classifier produces useful predictions.
A baseline classifier sets a performance floor for future models. You will test it on held-out flowers to discover what its accuracy score really represents.
In this step, get ready to:
- Create a repeatable train/test split.
- Fit a most-frequent baseline with the training labels.
- Inspect the baseline's held-out predictions.
Build the held-out baseline
A train/test split reserves part of the dataset for an honest check. The baseline learns from the training labels before it predicts the test flowers.
- Add a code cell beneath the scatter plot by using the notebook toolbar.
- Paste the complete baseline test into the new cell:
X_train, X_test, y_train, y_test = train_test_split(
X,
y,
random_state=0,
)
baseline = DummyClassifier(strategy="most_frequent")
baseline.fit(X_train, y_train)
baseline_predictions = baseline.predict(X_test)
baseline_accuracy = accuracy_score(y_test, baseline_predictions)
print(
"First 10 baseline predictions:",
iris.target_names[baseline_predictions[:10]],
)
print(f"Baseline accuracy: {baseline_accuracy:.3f}")
What does this code do?
- The train_test_split call separates the feature matrix and label array into training and test sets.
- The random_state=0 setting produces the same split each time.
- The DummyClassifier(strategy="most_frequent") estimator establishes a benchmark from the training labels.
- The accuracy_score call measures how many held-out labels match the baseline predictions.
Before you run this cell, how many different species names do you think its first ten predictions will contain?
- Run the new code cell with the play button on its left.
You'll see one output line containing predicted species names. You'll see a second output line containing the baseline accuracy.
Cell Not Producing Two Output Lines?
- Run the earlier data cell again if the output says a dataset variable is missing.
- Run the import cell again if the output mentions a missing classifier or metric.
If the cell still stops early, help me troubleshoot the baseline cell in my flower classifier notebook.
✔️ Awesome, I've got everything!
Your notebook now contains a completed baseline cell beneath the scatter plot.
ⓧ I'd like to double check the full code
!pip install scikit-learn==1.9.1 matplotlib==3.11.2
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import ConfusionMatrixDisplay, accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
iris = load_iris()
X = iris.data
y = iris.target
print("Sample count:", X.shape[0])
print("Feature names:", iris.feature_names)
print("Species names:", iris.target_names)
print("First five labeled samples:")
for measurements, species_index in zip(X[:5], y[:5]):
named_measurements = dict(zip(iris.feature_names, measurements))
print(named_measurements, "->", iris.target_names[species_index])
figure, ax = plt.subplots()
for class_index, class_name in enumerate(iris.target_names):
ax.scatter(
X[y == class_index, 2],
X[y == class_index, 3],
label=class_name,
alpha=0.7,
)
ax.set_xlabel(iris.feature_names[2])
ax.set_ylabel(iris.feature_names[3])
figure.suptitle("Iris Flower Measurements")
ax.legend()
plt.show()
X_train, X_test, y_train, y_test = train_test_split(
X,
y,
random_state=0,
)
baseline = DummyClassifier(strategy="most_frequent")
baseline.fit(X_train, y_train)
baseline_predictions = baseline.predict(X_test)
baseline_accuracy = accuracy_score(y_test, baseline_predictions)
print(
"First 10 baseline predictions:",
iris.target_names[baseline_predictions[:10]],
)
print(f"Baseline accuracy: {baseline_accuracy:.3f}")
Inspect the baseline shortfall
A baseline is useful because its behavior is easy to inspect. Its result sets the minimum score that a learned classifier needs to beat.
- Count the distinct species names in the first output line.
- Compare that count with the three species names printed earlier.
- Read the accuracy value in the second output line.
All ten predictions show the same species name. The baseline accuracy appears immediately below them.
You've exposed the baseline's weakness: it repeats the most frequent class without reacting to any flower measurement. Its accuracy now gives you a concrete performance floor.
Your baseline now gives the next classifier a score to beat. Next, you'll train a pipeline that learns from the flower measurements.
Train and Evaluate Your Model
Your baseline proved that one repeated guess cannot respond to flower measurements. You now have a clear performance floor to beat.
A scikit-learn preprocessing pipeline scales the four features before learning their relationship to each species. The held-out flowers then reveal how well that relationship works on unseen data.
In this step, get ready to:
- Combine feature scaling with logistic regression in one pipeline.
- Compare the model's held-out accuracy with the baseline accuracy.
- Display a labeled confusion matrix for the held-out predictions.
Build and compare the pipeline
The StandardScaler() component puts the measurements on comparable scales. LogisticRegression() learns how those scaled measurements relate to the three species.
- Use the add-cell control beneath the baseline cell to create a new code cell.
- Add the training and comparison logic to the new cell by pasting this code:
model = make_pipeline(
StandardScaler(),
LogisticRegression(),
)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
model_accuracy = accuracy_score(y_test, predictions)
print(f"Baseline accuracy: {baseline_accuracy:.3f}")
print(f"Model accuracy: {model_accuracy:.3f}")
print("Model beats baseline:", model_accuracy > baseline_accuracy)
What does this code do?
- The make_pipeline function keeps scaling before classification in a fixed sequence.
- The model.fit call uses only X_train with y_train.
- The scaler learns its scaling values from the training features.
- The classifier learns how the training measurements connect to each species.
- The model.predict call produces one prediction for each held-out flower.
- The accuracy_score function measures the share of held-out predictions that match their labels.
- The final comparison checks whether the trained model exceeds the baseline result.
Before you run this cell, do you think a model that learns from all four measurements will beat the repeated baseline guess?
- Run the new cell using the play button on its left.
- Wait for the notebook's saving indicator to finish.
You'll see the baseline accuracy followed by a higher model accuracy. The final comparison reports that the model beats the baseline.
That is the key leap. Your classifier now responds to flower measurements instead of repeating one species.
Model cell not completing?
Confirm that you ran the earlier cells from the installation cell through the baseline cell. The training code depends on the imports with the four split arrays.
Check that X_train uses a capital X. Help me troubleshoot my model training cell.
Display the confusion matrix
A confusion matrix places actual species beside predicted species. Counts on the diagonal are correct predictions while off-diagonal counts reveal specific mistakes.
- Place your cursor below the final print line in the model cell.
- Append the labeled evaluation chart by pasting this code:
ConfusionMatrixDisplay.from_predictions(
y_test,
predictions,
display_labels=iris.target_names,
)
plt.show()
What does this code do?
- The ConfusionMatrixDisplay.from_predictions method compares the held-out labels with the model's predictions.
- The display_labels argument shows species names in place of numeric classes.
- The plt.show() call displays the completed chart in the notebook.
Before you rerun the cell, where do you expect most of the counts to appear if the model learned useful patterns?
- Rerun the model cell using the play button on its left.
- Wait for the notebook's saving indicator to finish.
You'll see both accuracy scores above a labeled three-by-three confusion matrix. Most counts sit on the diagonal.
You'll also see one off-diagonal count from the held-out test set. That cell identifies a specific flower the model classified incorrectly.
Confusion matrix not appearing?
Confirm that plt.show() is the final line in the cell. Check that the earlier prediction line created predictions before the chart code runs.
If the axes show numbers instead of species names, compare the display_labels line with the reference below. Help me fix my confusion matrix.
✔️ Awesome, I've got everything!
Great. Double-check that the notebook has saved your completed model cell.
ⓧ I'd like to double check the full code
Cell 1:
!pip install scikit-learn==1.9.1 matplotlib==3.11.2
Cell 2:
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import ConfusionMatrixDisplay, accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
Cell 3:
iris = load_iris()
X = iris.data
y = iris.target
print("Sample count:", X.shape[0])
print("Feature names:", iris.feature_names)
print("Species names:", iris.target_names)
print("First five labeled samples:")
for measurements, species_index in zip(X[:5], y[:5]):
named_measurements = dict(zip(iris.feature_names, measurements))
print(named_measurements, "->", iris.target_names[species_index])
Cell 4:
figure, ax = plt.subplots()
for class_index, class_name in enumerate(iris.target_names):
ax.scatter(
X[y == class_index, 2],
X[y == class_index, 3],
label=class_name,
alpha=0.7,
)
ax.set_xlabel(iris.feature_names[2])
ax.set_ylabel(iris.feature_names[3])
figure.suptitle("Iris Flower Measurements")
ax.legend()
plt.show()
Cell 5:
X_train, X_test, y_train, y_test = train_test_split(
X,
y,
random_state=0,
)
baseline = DummyClassifier(strategy="most_frequent")
baseline.fit(X_train, y_train)
baseline_predictions = baseline.predict(X_test)
baseline_accuracy = accuracy_score(y_test, baseline_predictions)
print(
"First 10 baseline predictions:",
iris.target_names[baseline_predictions[:10]],
)
print(f"Baseline accuracy: {baseline_accuracy:.3f}")
Cell 6:
model = make_pipeline(
StandardScaler(),
LogisticRegression(),
)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
model_accuracy = accuracy_score(y_test, predictions)
print(f"Baseline accuracy: {baseline_accuracy:.3f}")
print(f"Model accuracy: {model_accuracy:.3f}")
print("Model beats baseline:", model_accuracy > baseline_accuracy)
ConfusionMatrixDisplay.from_predictions(
y_test,
predictions,
display_labels=iris.target_names,
)
plt.show()
Your held-out evaluation now proves that the trained pipeline beats the baseline. Next, you will turn this model into a prediction demo for one new flower.
Predict a New Flower
Your trained pipeline now measures performance on held-out flowers. An accuracy score still feels abstract during a live demo.
In this step, you'll add one editable measurement row to your Google Colab notebook. The fitted model turns that row into a species name.
In this step, get ready to:
- Add one editable row with four features in the documented order.
- Print the pipeline's prediction as a species name.
- Prove the notebook works from top to bottom.
Add the prediction cell
The new_flower row must follow the same order as iris.feature_names. The code keeps all four measurements together so the pipeline receives one complete sample.
- Add a blank code cell directly beneath Cell 6 using the notebook's insert control.
- Paste this code into the blank cell:
new_flower = [[5.9, 3.0, 5.1, 1.8]]
predicted_class = model.predict(new_flower)[0]
predicted_species = iris.target_names[predicted_class]
print("Predicted species:", predicted_species)
What does this code do?
- The new_flower value stores one sample in the same order as iris.feature_names.
- The model.predict(new_flower) call sends the sample through the trained pipeline. The [0] selection takes the first result.
- The iris.target_names[predicted_class] lookup converts the numeric class into a readable species name.
- The print call makes the final result visible in the notebook.
Before you run Cell 7, which species do you expect these four measurements to resemble?
- Run Cell 7 by selecting its play button.
You'll see Predicted species: followed by one of the three Iris species names.
There it is. Your classifier has completed its first editable prediction.
Prediction cell not completing?
- Run Cell 6 again if the prediction cell reports that an earlier variable is missing.
- Check that new_flower has two outer brackets around its four values.
- Compare the three prediction lines with the code block above.
Help me diagnose why my flower prediction cell is not completing.
✔️ Awesome, I've got everything!
Cell 7 now turns one measurement row into a readable species name.
ⓧ I'd like to double check the full code
!pip install scikit-learn==1.9.1 matplotlib==3.11.2
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.dummy import DummyClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import ConfusionMatrixDisplay, accuracy_score
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
iris = load_iris()
X = iris.data
y = iris.target
print("Sample count:", X.shape[0])
print("Feature names:", iris.feature_names)
print("Species names:", iris.target_names)
print("First five labeled samples:")
for measurements, species_index in zip(X[:5], y[:5]):
named_measurements = dict(zip(iris.feature_names, measurements))
print(named_measurements, "->", iris.target_names[species_index])
figure, ax = plt.subplots()
for class_index, class_name in enumerate(iris.target_names):
ax.scatter(
X[y == class_index, 2],
X[y == class_index, 3],
label=class_name,
alpha=0.7,
)
ax.set_xlabel(iris.feature_names[2])
ax.set_ylabel(iris.feature_names[3])
figure.suptitle("Iris Flower Measurements")
ax.legend()
plt.show()
X_train, X_test, y_train, y_test = train_test_split(
X,
y,
random_state=0,
)
baseline = DummyClassifier(strategy="most_frequent")
baseline.fit(X_train, y_train)
baseline_predictions = baseline.predict(X_test)
baseline_accuracy = accuracy_score(y_test, baseline_predictions)
print(
"First 10 baseline predictions:",
iris.target_names[baseline_predictions[:10]],
)
print(f"Baseline accuracy: {baseline_accuracy:.3f}")
model = make_pipeline(
StandardScaler(),
LogisticRegression(),
)
model.fit(X_train, y_train)
predictions = model.predict(X_test)
model_accuracy = accuracy_score(y_test, predictions)
print(f"Baseline accuracy: {baseline_accuracy:.3f}")
print(f"Model accuracy: {model_accuracy:.3f}")
print("Model beats baseline:", model_accuracy > baseline_accuracy)
ConfusionMatrixDisplay.from_predictions(
y_test,
predictions,
display_labels=iris.target_names,
)
plt.show()
new_flower = [[5.9, 3.0, 5.1, 1.8]]
predicted_class = model.predict(new_flower)[0]
predicted_species = iris.target_names[predicted_class]
print("Predicted species:", predicted_species)
Rerun the complete notebook
A self-contained notebook recreates every required variable from its saved cells. Running from the first cell proves the final prediction does not depend on hidden runtime state.
Before you rerun everything, do you expect Cell 7 to work using only the cells above it?
- Use the Runtime menu's run-all control to execute Cells 1 through 7 from top to bottom.
What should I see?
- The data cells print five labeled samples.
- The plotting cell displays three labeled groups on the scatter plot.
- The baseline cell prints ten identical species predictions plus its accuracy score.
- The model cell prints both accuracy scores. It also displays the labeled confusion matrix.
- The final cell prints Predicted species: followed by one Iris species name.
That full run proves the notebook recreates its result from the saved cells. You now have a shareable flower classifier that anyone can rerun from top to bottom.
Run-all stopped early?
- Select the first cell that did not complete.
- Compare that cell with the matching section in the full-notebook tab above.
- Run the corrected cell on its own.
- Use the run-all control again after the corrected cell succeeds.
Help me find why my flower classifier notebook stops during a complete run.
Secret mission
Investigate the Model's Mistake
Find one held-out flower that the trained model classified incorrectly. You will connect its measurements to an overlapping region in the scatter plot.
Clean Up Your Resources
Clean Up Your Resources
Choose how you want to leave your notebook. This Google Colab project is free of charge.
Resources you used:
- A completed Google Colab notebook named flower_classifier.ipynb stored in Google Drive.
Keep everything running
No action is needed while you are still using the notebook. Keeping it in Google Drive creates no ongoing project cost.
- Leave flower_classifier.ipynb in Google Drive.
Pause - I'll come back to this later
Closing the current browser tab lets the temporary runtime disconnect. Your saved notebook remains available in Google Drive.
- Close the browser tab containing flower_classifier.ipynb.
Delete - I don't want to use this again
Deletion becomes permanent after the trash is emptied. Emptying it also removes any other files already there.
- Open Google Drive in another browser tab.
- Find flower_classifier.ipynb in Google Drive.
- Move flower_classifier.ipynb to the Google Drive trash.
- Open the Google Drive trash.
- Confirm the trash contains no other files you want to keep.
- Empty the Google Drive trash.
The notebook no longer remains in Google Drive. Your temporary runtime needs no separate cleanup.
Nice Work!
Nice Work!
You did it! You built a shareable Google Colab notebook that turns four Iris flower measurements into a species prediction.
You've learned how to:
- Explore the Iris dataset with a color-coded scatter plot that reveals species patterns.
- Compare a deliberately weak baseline with a trained preprocessing and logistic-regression pipeline.
- Measure held-out model performance with accuracy and a labeled confusion matrix. Use the trained model to classify a new flower.
- Secret Mission: Isolate one misclassified test flower and explain the confusion using its measurements and the scatter plot.
Ready to quiz yourself?