DEV Community

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

Posted on • Edited on

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

Step into the shadowy dungeons of Hogwarts, young spellcasters, where the air hums with bubbling cauldrons and the scent of mischief! I’m Professor Gerry Leo Nugroho, your potion-brewing companion, and today we’re sneaking into Professor Snape’s lair to whip up something dazzling: colorful charts that dance like fire crabs on a moonlit night. With our Iris Dataset scroll as our recipe, we’ll stir numbers into magical visualizations—pictures that leap off the parchment and dazzle the eyes of every witch and wizard!


Chapter 3. Potion Brewing: Stirring Up Magical Visualizations 🧪

Gemika Haziq Nugroho, my fearless 9-year-old Gryffindor, clutches his tiny cauldron, peering at me with a grin. “Abi, are we making the flowers glow like Fawkes the Phoenix?” he chirps. Oh, my little lion, we’re doing even better—we’re brewing visual potions that show Setosa’s short petals, Versicolor’s fiery spirit, and Virginica’s grand sweep, all twirling in colors brighter than a Weasley Wizard Wheezes prank! These charts aren’t just pretty—they’re spells that tell stories, perfect for impressing even the sour-faced Snape.

This isn’t just potion class—it’s magic with a twist! Like Hermione perfecting her Polyjuice Potion, we’ll mix measurements with creativity, turning dull numbers into a bubbling brew of wonder. So, grab your ladle, Gemika, and let’s stir up some enchantment that’d make Dumbledore’s beard twitch with delight! 🧙‍♂️✨


3.1 The Code & Algorithm

Time to brew our visual potions with Python’s finest tools—matplotlib, seaborn, and plotly—our magical ingredients! Here’s the spell to conjure dancing charts in Jupyter Lab:

import pandas as pd  # 📜 Summon the potion master: Pandas for data wizardry!
import matplotlib.pyplot as plt  # 🎨 Matplotlib, the enchanted canvas for spells (plots)!
import seaborn as sns  # 🌊 Seaborn, the ocean of visualization magic!
import plotly.express as px  # ✨ Plotly, the interactive crystal ball of data!
import matplotlib.font_manager as fm  # 🎭 Font manager to support emoji rendering

# 🖋️ Set a font that supports emojis to avoid missing glyph errors
plt.rcParams['font.family'] = 'Arial Unicode MS'  # macOS users
# Uncomment the correct one for your OS:
# plt.rcParams['font.family'] = 'Segoe UI Emoji'  # Windows users
# plt.rcParams['font.family'] = 'Noto Sans'  # Linux users

# 📖 Fetch the legendary Iris scroll, an ancient text of floral secrets!
try:
    iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')
    print("📜 The Iris scroll has been successfully summoned!\n")
except Exception as e:
    print(f"⚠️ Alas! The spell failed: {e}")
    exit()

# 🔮 Peek inside the scroll—what secrets lie within?
print("\n✨ First 5 magical blooms:")
print(iris.head())  # Display the first 5 rows of the dataset
print("\n")

# 🧙‍♂️ Unveiling the grand structure of the scroll (columns)
print("📝 The Iris spellbook contains these enchanted fields:")
print(iris.columns.tolist())

# 🔍 Detecting missing spells—er, values!
print("\n🕵️‍♂️ Are there any missing ingredients?")
print(iris.isnull().sum())  # Checking for missing values

# 🌸 Unique species in the magical garden
print("\n🌺 Types of enchanted flowers in the dataset:")
print(iris['species'].unique())

# 🎭 Brew a scatter plot with seaborn—like fire crabs dancing at the Yule Ball!
plt.figure(figsize=(8,6))  # Adjusting the cauldron (figure size) for better visibility
sns.scatterplot(
    x='sepal_length', y='petal_length', hue='species', size='petal_width', data=iris
)
plt.title('Snape’s Enchanted Flower Dance')  # Removed emojis to prevent missing glyph errors
plt.xlabel("Sepal Length")
plt.ylabel("Petal Length")
plt.legend(title='House of Flowers')  # A magical touch to the legend
plt.show()

# ✨ Stir an interactive Plotly potion—wave your wand to zoom and explore!
fig = px.scatter(
    iris, x='sepal_length', y='petal_length', color='species', size='petal_width',
    title='Magical Iris Potion Glow', labels={"sepal_length": "Sepal Length", "petal_length": "Petal Length"}
)
fig.show()
Enter fullscreen mode Exit fullscreen mode
✨ First 5 magical blooms:
   sepal_length  sepal_width  petal_length  petal_width species
0           5.1          3.5           1.4          0.2  setosa
1           4.9          3.0           1.4          0.2  setosa
2           4.7          3.2           1.3          0.2  setosa
3           4.6          3.1           1.5          0.2  setosa
4           5.0          3.6           1.4          0.2  setosa


📝 The Iris spellbook contains these enchanted fields:
['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'species']

🕵️‍♂️ Are there any missing ingredients?
sepal_length    0
sepal_width     0
petal_length    0
petal_width     0
species         0
dtype: int64

🌺 Types of enchanted flowers in the dataset:
['setosa' 'versicolor' 'virginica']
Enter fullscreen mode Exit fullscreen mode

Cast this, and—whoosh!—a rainbow of dots bursts forth, each flower species glowing in its own hue, wiggling with size and sparkle!

Gemika Haziq Nugroho - Gerry Leo Nugroho - Iris Dataset - 01

Gemika claps, “It’s like the Great Hall ceiling on Halloween!” Spot on, my young brewer—seaborn paints a quick, fiery scatter plot, while plotly adds a magical twist: hover, zoom, and twirl the chart like a spellbook come alive! Sepal lengths stretch across, petal lengths rise up, and colors shout “Setosa! Versicolor! Virginica!”—a potion so vivid, even Snape might crack a smirk.

Gemika Haziq Nugroho - Gerry Leo Nugroho - Iris Dataset - 02

This is no ordinary brew—it’s a cauldron of insight! Matplotlib lays the base, seaborn adds flair, and plotly brings the wow, letting us poke and prod the magic. Stir these tools together, and we’ve got visualizations that dance better than a Hippogriff at the Yule Ball! 🦇🎨


3.2 Hogwarts Application

Imagine Dumbledore summoning us to his office, his eyes twinkling behind half-moon spectacles. “Gerry, I need a map of the Forbidden Forest—something to track those pesky Acromantulas!” With our visual potions, we’d chart the forest’s secrets: scatter plots marking tree heights, colors for creature lairs, sizes for danger levels—Aragog’s web glowing red! It’s a magical map that moves, perfect for Harry’s next adventure or Hagrid’s midnight patrols.

Gemika bounces, “Can we find unicorns too, Abi?” Absolutely! Picture us plotting shimmering hoofprints in silver, or graphing Centaur star-gazing spots. These charts aren’t just for forests—they could track Quidditch broom paths for Madam Hooch or glow with potion strengths for Snape’s next detention-worthy brew. At Hogwarts, visualizations turn chaos into clarity, like a Patronus chasing away Dementors!

This is wizardry for the bold—like Ron charming his rat (well, almost). By brewing these graphs, we help Dumbledore, dazzle Sprout, or even outsmart Filch’s sneaky corridors. Our Iris charts are just the start—soon, we’ll map the whole magical world! 🌲✨


3.3 Quiz from Gemika Haziq Nugroho

Gemika swirls his ladle, giggling like a pixie. “Abi, which potion makes the Iris flowers glow on a chart?

  • A) A boring old Pepperup Potion—snore!
  • B) A dazzling mix of seaborn and plotly spells—shiny and wiggly!
  • C) A sneaky Slytherin trick that hides the flowers—boo!

What’s your pick, clever potion-maker? Hint: Think of what makes fire crabs dance! 🦁🧪


3.4 Next Chapter

Hold your Hippogriffs, young wizards—next, we’ll peer into the Owl’s Insight, spotting patterns in our Iris blooms like a Seer with a crystal ball! We’ll use magical tricks to find friendships and feuds among the numbers, preparing us for predictions that’ll make even McGonagall raise an eyebrow. Get ready—our cauldron’s just warming up!

Top comments (0)