DEV Community

Cover image for Gemika’s Enchanted Guide to Iris Dataset with Magic and Machine Learning 🌟🧙‍♂️ (Part #4)
gerry leo nugroho
gerry leo nugroho

Posted on

Gemika’s Enchanted Guide to Iris Dataset with Magic and Machine Learning 🌟🧙‍♂️ (Part #4)

Greetings again, my daring young spellcasters! In our last adventure, we stirred bubbling cauldrons with Professor Snape, brewing dazzling visualizations that danced like fire crabs across our magical parchment. We used seaborn and plotly to paint the Iris Dataset’s secrets—Setosa’s tiny petals, Versicolor’s fiery flair, and Virginica’s grand sweep—turning numbers into a glowing potion of wonder that even Gemika, my 9-year-old Gryffindor, couldn’t stop giggling over!

So far, we’ve met the Iris flowers with the Sorting Hat, peeked at their quirks with EDA, and made them shimmer with charts. Now, we’re stepping into a new chamber of Hogwarts’ mysteries, where the air hums with whispers of hidden truths. Grab your wands, young witches and wizards, because we’re about to gaze into something truly enchanting! 🌟🪄


Chapter 4. The Mirror of Erised: Finding Insights in the Data 🦇

Welcome to the flickering glow of the Mirror of Erised, where secrets shimmer like stars in the night sky! I’m Professor Gerry Leo Nugroho, your guide, and today we are peering into the Iris Dataset to uncover hidden patterns in its petals and sepals—truths as deep as the desires the Mirror shows Harry. Are the flowers’ lengths and widths tied together like Ron and Hermione bickering, or do they stand apart like Draco sulking in a corner?Let’s find out!

Gemika tugs my robe, his eyes wide as Quaffles. “Abi, is this like seeing the future?” he whispers. Close, my little lion cub—it’s more like spotting clues in the present, as if the Mirror whispered, “Look closer, these petals and sepals are friends!” We’ll use a magical spell called correlation to see how these traits dance together—maybe petal length grows with sepal length, or maybe they’re as unrelated as Hagrid and a quiet day. It’s detective work with a wand, and we’re the Hogwarts sleuths!

This isn’t just gazing for fun—it’s wisdom for our brewing! Like Harry learning the Mirror shows his heart, we’ll learn what drives these flowers, turning numbers into tales of magic. With every peek, we’re one step closer to predicting their species, as thrilling as catching the Snitch in a storm! So, Gemika, let’s polish our mirror and dive into the reflections! 🌸✨


4.1 The Code & Algorithm

Time to cast our insight spell with Python’s finest tools—pandas and seaborn—our crystal ball and quill! Here’s the incantation for Jupyter Lab:

# Summon the magical tools  
import pandas as pd  
import seaborn as sns  
import matplotlib.pyplot as plt  

# Fetch the Iris scroll  
iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')  

# Cast the correlation charm—like gazing into the Mirror!  
correlation = iris.corr(numeric_only=True)  
print("Mirror’s whispers:")  
print(correlation)  

# Brew a heatmap potion—colors that glow!  
sns.heatmap(correlation, annot=True, cmap='coolwarm', square=True)  
plt.title('The Mirror of Erised’s Heatmap')  
plt.show()  
Enter fullscreen mode Exit fullscreen mode
📜 The ancient scroll has been successfully retrieved!

🔮 Mirror’s whispers—revealing hidden connections:
              sepal_length  sepal_width  petal_length  petal_width
sepal_length      1.000000    -0.117570      0.871754     0.817941
sepal_width      -0.117570     1.000000     -0.428440    -0.366126
petal_length      0.871754    -0.428440      1.000000     0.962865
petal_width       0.817941    -0.366126      0.962865     1.000000
Enter fullscreen mode Exit fullscreen mode

Wave your wand, and—poof!—a table of numbers appears, followed by a glowing heatmap where reds and blues swirl like potion fumes!

Gemika Haziq Nugroho - Gerry Leo Nugroho - Figure - 04

Gemika gasps, “It’s like a treasure map!” Exactly, my young wizard—corr() reveals how traits like petal length and sepal width connect (1.0 means they’re twins, 0 means strangers!). The heatmap paints it vivid: red for strong bonds (like petal_length and petal_width at 0.96!) and blue for weak ones. It’s our Mirror of Erised, showing not desires, but the flowers’ secret friendships—simple yet dazzling as a charm! 🧙‍♂️📊

Ah, young wizard, gaze upon the Mirror of Erised’s Heatmap and listen closely—for it whispers secrets of the Iris flowers, much like the enchanted portraits in the halls of Hogwarts! 🪞✨


4.1.1 🔮 The Mirror’s Whispers – Deciphering the Correlations

As you peer into the matrix of numbers, each cell tells a tale of how the different attributes of the Iris flowers intertwine, much like the bonds between wizarding families. The values range from -1 to 1, revealing friendships and feuds among the features:

  1. Petal length and petal width (🔥 0.96 🔥)

    A bond stronger than Harry and Hermione—inseparable and always in agreement! If petal length grows, petal width follows, like the way best friends always walk side by side.

  2. Sepal length and petal length (🌟 0.87 🌟)

    Not quite as close as our previous duo, but still a firm alliance, like Fred and George Weasley—always scheming together in harmony. A longer sepal length often hints at a longer petal length too!

  3. Sepal width and the rest (⚡ Low correlations ⚡)

    Ah, sepal width is the lone wolf, the Snape of our dataset—keeping its distance from petal length, petal width, and even its own sepal length! Its correlation values hover around -0.12 to -0.36, suggesting it doesn’t always follow the crowd.

  4. The cool and warm colors in the heatmap (🧙‍♂️)

    The reds and oranges reveal strong friendships, like the Gryffindor camaraderie, while the deep blues expose oppositions, like the clash of Harry and Draco.


4.1.2 🏺 What Do These Magical Numbers Tell Us?

  • Petal dimensions are deeply connected, meaning a flower with a longer petal tends to have a wider one too.
  • Sepal width is the rebellious one, dancing to its own rhythm, rarely influenced by the other floral parts.
  • If you know one petal measurement, you can predict the others with great accuracy, much like how Dumbledore always seemed to know what was coming next!

4.1.3 🧙 Wizardly Wisdom

Should you find yourself in a magical greenhouse, hoping to classify an unknown Iris flower, remember: petal measurements will guide your path more than sepals ever will. Trust in the magic of numbers, young scholar, for they hold powers greater than you know! 🌟✨


4.2 Hogwarts Application

Picture the Quidditch pitch, brooms zooming under a stormy sky, and Oliver Wood shouting, “Gerry, can you predict if Gryffindor will win?” With our correlation magic, we can! Imagine charting broom speeds, player heights, and Snitch sightings—our heatmap glows red where speed and wins link tight, blue where height doesn’t matter. It’s like peering into the Mirror to see Gryffindor’s triumph before the whistle blows!

Gemika cheers, “Can we beat Slytherin, Abi?” Oh, yes! We’d spot patterns—maybe fast seekers win more, or strong Beaters dodge Bludgers best. This isn’t just for Quidditch—it could track OWL scores for McGonagall or guess potion mishaps for Snape. At Hogwarts, insights turn chaos into victory, like Harry outsmarting Quirrell with a glance! 🏆✨


4.3 Quiz from Gemika Haziq Nugroho

Gemika tilts his head, twirling his wand. “Abi, what does the mirror show about the Iris flowers?

  • A) They’re all secretly Mandrakes screaming at each other—eek!
  • B) How their petals and sepals are connected, like friends holding hands!
  • C) Just a pretty picture with no meaning, like Peeves’ doodles!

What’s your guess, clever spellcaster? Hint: Think of what the heatmap’s colors whisper! 🦁🌟


4.4 Next Chapter

Next time, we’ll tiptoe into the Hogwarts workshops with Professor McGonagall, wielding a Reparo charm to fix our dataset—polishing it shiny as a new broomstick! Get ready, young wizards, for a spellbinding clean-up! 🧹✨ There’s our fourth chapter, shimmering with reflections and riddles! What say you—tweak this potion, or brew the next one fresh? 🌟🪞

Top comments (0)