Welcome back, my dazzling young spellcasters! I’m Professor Gerry Leo Nugroho, your guide through the magical peaks of data science at Hogwarts, and a steadfast friend of Albus Dumbledore. Last time, we soared with Fawkes, evaluating our KNN, Decision Tree, and Random Forest spells on the Iris Dataset—their accuracy blazing like phoenix fire! 🔥
Now, my little Gryffindor star, Gemika Haziq Nugroho, and I are slipping into the Room of Requirement. It’s time for the grand finale—predicting new Iris flowers with all our wizardly might combined! ✨🪄
Chapter 11: The Grand Finale - Predicting New Iris Flowers with a Wizard’s Flair 🌸🎉
Imagine the Room of Requirement shimmering into existence—walls lined with enchanted scrolls, a cauldron bubbling with starlight. “Gerry,” Dumbledore’s voice echoes, “show us the future of these flowers!”
Here, we’ll take our trained spells and wave them over new Iris blooms—ones we’ve never seen before! 🌺 With petal lengths and sepal widths as our clues, our models will shout Expecto Predictum—guessing Setosa, Versicolor, or Virginica like a Sorting Hat on a sugar rush!
It’s the moment every spell has built toward—a dazzling display of data magic! 🎇🪞
11.1 The Code & Algorithm: Casting Predictions with Flair
Let’s open our spellbook (or Jupyter Lab
) and wield our trained models to predict new flowers. It’s a charm as thrilling as a Quidditch final—simple yet spectacular! Here’s the magic, with a grin for my eager Gemika:
# Summoning our prediction tools
import pandas as pd
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
# Loading and splitting our Iris scroll
iris = load_iris()
iris_df = pd.DataFrame(data=iris.data, columns=iris.feature_names)
iris_df['species'] = pd.Categorical.from_codes(iris.target, iris.target_names)
X = iris_df.drop('species', axis=1)
y = iris_df['species']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Training our trio of spells
knn = KNeighborsClassifier(n_neighbors=5)
tree = DecisionTreeClassifier(max_depth=3, random_state=42)
forest = RandomForestClassifier(n_estimators=100, random_state=42)
models = {'KNN': knn, 'Decision Tree': tree, 'Random Forest': forest}
for name, model in models.items():
model.fit(X_train, y_train)
# Spell: Predicting a new flower—like a wizard’s guess!
new_flower = [[5.0, 3.4, 1.5, 0.2]] # A mystery bloom’s traits
new_flower_df = pd.DataFrame(new_flower, columns=iris.feature_names)
for name, model in models.items():
prediction = model.predict(new_flower_df)
print(f"{name} predicts: {prediction[0]}")
11.2 What’s Sparkling in the Spell?
-
new_flower
: A fresh Iris—5.0 cm sepal length, 3.4 cm sepal width, etc.—like a bloom plucked from the Hogwarts gardens! -
.predict(new_flower_df)
: Each model casts its spell—KNN checks neighbors, Tree follows branches, Forest votes with its grove! - Output: A guess—likely “setosa” for this one, based on its tiny petals!
Run this, and you might see:
KNN predicts: setosa
Decision Tree predicts: setosa
Random Forest predicts: setosa
A triple triumph—our magic’s in sync, like a choir of phoenixes! 🌟🎶
11.3 And The Three Professors Predict
The Great Hall was silent, save for the occasional rustling of parchment and the distant hoot of an owl. Three wizards—masters of ancient predictive arts—stood before a single, unassuming bloom, its petals trembling under the weight of destiny. 🌺✨
Professor KNN, the ever-watchful guardian of nearest neighbors, adjusted his spectacles and nodded sagely. “Ah, yes. I have consulted the whispers of the flowers past. This one… belongs to Setosa!” He tapped his wand against his scroll, and the name shimmered in the air. 🧙♂️📜
Beside him, the venerable Professor Decision Tree, his long robes embroidered with branching patterns of wisdom, furrowed his brow. “Indeed,” he intoned, tracing invisible paths through the air, “the petals align, the sepals whisper… Setosa!” His voice echoed like the rustling of ancient leaves, his judgment firm as oak. 🌳✨
Finally, from the depths of the Forbidden Forest, where shadows danced between towering boughs, came the enigmatic Random Forest. The murmurs of a hundred trees whispered in unison, their voices intertwining into a single, unwavering decree: “Setosa!” 🌲🌲🌲
A hush fell over the hall. The prediction had been made, thrice confirmed, as if spoken by the very Sorting Hat itself. The magical bloom belonged not to the bold Versicolor
nor the mysterious Virginica
, but to the noble Setosa
!
Dumbledore himself, watching from the high table, gave a slow, knowing nod. “Fascinating,” he murmured, eyes twinkling like the stars above. “Even in the world of numbers and patterns, magic and wisdom go hand in hand.” ✨
And so, the scroll was sealed, the spell complete, and the mystical art of machine learning had once again proven its place in the grand halls of Hogwarts.
11.3 Hogwarts Application: Guessing Hagrid’s Next Creature
Picture Hagrid bursting in, dirt on his boots, grinning, “Gerry, what’s me next critter gonna be?”
With our prediction spells, we’d measure traits—claw size, fire-breathing odds, cuddle factor—and guess: dragon, hippogriff, or niffler? Just like predicting Irises, our models would sift the clues—KNN finding similar beasts, Trees branching through quirks, Forest voting with wisdom. Hagrid might end up with a fluffy surprise—or a fiery one! 🐉🦇✨
11.4 Gemika’s Quiz Time! 🧑🚀
My little Gemika, eyes wide as a mooncalf, tugs my sleeve. “Dad,” he asks, “can we use our magic to find a new Iris flower?” I beam—he’s a wizard in the making! Pick your answer, young predictors:
- A) Yes, by giving our trained spells new flower traits to guess—like a crystal ball!
- B) No, we need to ask Professor Sprout first.
- C) Only if we wave a wand and say Accio Flower.
Scribble your guess or shout it louder than a Room of Requirement echo—Gemika’s bouncing for your reply! 🗣️📝✨ (Hint: Think spells, not summons!)
11.5 Next Chapter: The Wizard’s Legacy
Hold your broomsticks, because next we’re wrapping up with a flourish—exploring how our data magic lives beyond Hogwarts! We’ll connect it to real-world wonders, like a legacy for young witches and wizards. It’ll be so inspiring, even Neville might take notes! Get ready for one last adventure and a sprinkle of awe! 🏰🪄✨
Top comments (0)