পাঠ ২১ · ২৫-এর মধ্যে · মডিউল ৩

EDA — Iris ডেটাসেটে

Mini EDA on Iris dataset — end-to-end
৮ মিনিট পড়া শুরু · Beginner ব্রাউজারেই কোড চালান

এই পাঠে যা শিখবেন

  • EDA workflow — যে ক্রমে প্রতিটি dataset খোলেন
  • Iris dataset-এর ইতিহাস ও তাৎপর্য
  • Shape, dtype, missing value check
  • describe(), value_counts() দিয়ে summary
  • Distribution plot — histogram, boxplot, violinplot
  • Pairplot, correlation heatmap — feature relationship
  • Baseline classifier — EDA insight মডেল-এ apply

১ · EDA কী, কেন

EDAExploratory Data AnalysisJohn Tukey-র ১৯৭৭-এর book থেকে — modeling-এর আগে data summary, plot, structure বোঝার phase। "Look at the data before fitting." আজকে data scientist-এর প্রথম কাজ। = পরীক্ষাগারে ঢোকার আগে প্রতিটি জার, বোতল, নলটি দেখে নেওয়া। কোনো column-এ ভুল মান? কোন class-এ সবচেয়ে কম sample? কোন দু'টি feature redundant? এই প্রশ্নগুলো না জেনে মডেল train করা = অন্ধকারে শুট। John Tukey ১৯৭৭-এ "EDA" শব্দ উদ্ভাবন — "data দেখো, plot করো, hypothesis পরে।"

EDA-র ৬টি universal step

১) Load & shape: কত row, কত column?
২) Dtype & missing: প্রতিটি column-এর type? NaN আছে কি?
৩) Class balance: target distribution কেমন?
৪) Univariate: প্রতিটি column distribution — histogram, boxplot।
৫) Bivariate: feature-target ও feature-feature relationship।
৬) Insight → action: কী model class, কী preprocessing?

২ · Iris — ML-এর "Hello World"

Iris datasetIris dataset১৯৩৬-এ statistician Ronald Fisher-এর "The use of multiple measurements in taxonomic problems" paper থেকে। ১৫০ ফুল × ৪ measurement (sepal length/width, petal length/width) × ৩ species (setosa, versicolor, virginica)। ML-এর সবচেয়ে taught dataset। — ১৯৩৬-এ Ronald Fisher-এর উপস্থাপিত। ১৫০টি ফুল, ৩টি প্রজাতি (setosa, versicolor, virginica), প্রতিটির ৪টি measurement। ছোট, পরিষ্কার, balanced — তাই শেখার দারুণ ক্ষেত্র। কিন্তু সাবধান: production data এত পরিষ্কার হয় না।

৩ · Step 1 — Load & first look

Python · load
import seaborn as sns
import pandas as pd
import numpy as np

# Seaborn-এ built-in version (target column = "species")
iris = sns.load_dataset("iris")

print("Shape:", iris.shape)           # (150, 5)
print("Columns:", list(iris.columns))
print("\n--- প্রথম ৫ row ---")
print(iris.head())
print("\n--- শেষ ৫ row ---")
print(iris.tail())

    
head() ও tail() — প্রথম-শেষ দু'দিকেই দেখা গুরুত্বপূর্ণ। অনেক dataset শেষে junk row, summary row, বা encoding artifact থাকে।

৪ · Step 2 — dtype, missing, duplicate

Python · sanity check
import seaborn as sns
iris = sns.load_dataset("iris")

print("--- dtype ---")
print(iris.dtypes)

print("\n--- missing per column ---")
print(iris.isna().sum())

print("\n--- duplicate row ---")
print("Total duplicates:", iris.duplicated().sum())

print("\n--- info() one-shot summary ---")
iris.info()

    
Iris-এ missing ০, duplicate ১-৩টি (data collection artifact)। Production data-তে ১০-৪০% missing স্বাভাবিক — এই step skip করা যায় না।

৫ · Step 3 — class balance

Python · class count
import seaborn as sns
import matplotlib.pyplot as plt

iris = sns.load_dataset("iris")

print("--- class balance ---")
print(iris["species"].value_counts())
print("\n--- proportion ---")
print((iris["species"].value_counts(normalize=True) * 100).round(1))

# Visual
plt.figure(figsize=(6, 3))
sns.countplot(data=iris, x="species", hue="species", legend=False, palette="Set2")
plt.title("Class balance — perfectly balanced")
plt.tight_layout()
plt.show()

    
Iris ৫০-৫০-৫০ — perfectly balanced। Production-এ rarely এমন। Imbalanced হলে — accuracy misleading, F1/AUC দেখুন; SMOTE বা class_weight ব্যবহার।

৬ · Step 4 — describe ও univariate distribution

Python · describe + dist
import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="whitegrid")
iris = sns.load_dataset("iris")

print("--- describe ---")
print(iris.describe().round(2))

# প্রতিটি numeric column-এর histogram, একই grid-এ
fig, axes = plt.subplots(2, 2, figsize=(10, 6))
num_cols = ["sepal_length", "sepal_width", "petal_length", "petal_width"]

for ax, col in zip(axes.flatten(), num_cols):
    sns.histplot(data=iris, x=col, hue="species",
                 kde=True, alpha=0.5, ax=ax)
    ax.set_title(col)

plt.tight_layout()
plt.show()

    
describe() দেখুন — std, min, max range বোঝা যায়। Histogram-এ petal_length-এ setosa পরিষ্কারভাবে আলাদা (small petal) — discriminative। sepal_width-এ ৩ class মিশ্রিত — দুর্বল feature।

৭ · Step 5 — relationship: pairplot ও heatmap

Python · pair + corr
import seaborn as sns
import matplotlib.pyplot as plt

sns.set_theme(style="ticks")
iris = sns.load_dataset("iris")

# (১) Pairplot — সব pair scatter + diagonal-এ KDE
g = sns.pairplot(iris, hue="species", diag_kind="kde",
                 palette="husl", height=2.0, corner=True)
g.fig.suptitle("Iris — pairwise structure", y=1.02)
plt.show()

# (২) Correlation heatmap — numeric feature
plt.figure(figsize=(6, 4))
corr = iris.select_dtypes("number").corr()
sns.heatmap(corr, annot=True, fmt=".2f", cmap="coolwarm",
            vmin=-1, vmax=1, square=True, linewidths=0.5)
plt.title("Feature correlation")
plt.tight_layout()
plt.show()

print("\n--- top correlated pairs ---")
print(corr.abs().unstack().sort_values(ascending=False)
      .drop_duplicates().head(6))

    
petal_length ও petal_width-এর correlation ~০.৯৬ — প্রায় redundant। ML মডেলে দু'টি একসাথে রাখলে multicollinearity বাড়ে। Linear মডেলে coefficient unstable; tree-based-এ feature importance split।
EDA pipeline — Iris থেকে শেখা load → check → describe → plot → relationship → action load load_dataset (150, 5) sanity check dtype, NaN, dup missing=0 class balance value_counts 50-50-50 describe mean, std, range numeric summary univariate histogram + KDE per feature bivariate pairplot scatter grid correlation heatmap multicollinearity insight petal > sepal simple model EDA-র সিদ্ধান্ত setosa fully separable; versicolor↔virginica কিছু overlap petal_length ↔ petal_width: r=0.96 → multicollinearity sepal_width discriminative নয়; feature drop বিবেচ্য → baseline: scaled LogisticRegression; cross-val ~০.৯৭ Modeling সিদ্ধান্ত — feature, model class, regularization EDA → hypothesis → minimal pipeline → cross-validate
EDA-র ৬টি step — load, sanity, balance, describe, distribution, relationship — Iris-এ। নিচে — সিদ্ধান্ত ও পরবর্তী modeling action।

৮ · Step 6 — insight থেকে baseline মডেল

EDA-র insight এখন apply। petal feature প্রধান, scaled logistic regression — যথেষ্ট।

Python · baseline
import seaborn as sns
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import Pipeline
from sklearn.model_selection import cross_val_score

iris = sns.load_dataset("iris")
X = iris.drop(columns=["species"]).values
y = iris["species"].values

pipe = Pipeline([
    ("scaler", StandardScaler()),
    ("clf",    LogisticRegression(max_iter=1000)),
])

scores = cross_val_score(pipe, X, y, cv=5, scoring="accuracy")
print(f"5-fold accuracy: {scores.mean():.3f} ± {scores.std():.3f}")

# শুধু petal feature-এ কেমন?
X_petal = iris[["petal_length", "petal_width"]].values
scores_p = cross_val_score(pipe, X_petal, y, cv=5, scoring="accuracy")
print(f"petal-only:       {scores_p.mean():.3f} ± {scores_p.std():.3f}")

    
৪ feature-এ ~০.৯৭, শুধু ২টি petal feature-এও প্রায় same — EDA-র prediction confirmed। অর্ধেক feature, একই accuracy: simpler, faster, more interpretable model।

৯ · Iris-এর সীমা — production reality

  • খুব ছোট: ১৫০ row — modern algorithm-এর জন্য toy।
  • খুব পরিষ্কার: missing ০, duplicate ~১, outlier কম। Real data-তে ৩০-৫০% effort cleanup-এ।
  • Linearly separable: setosa পুরোপুরি আলাদা; ML-এর কঠিন nuance এতে নেই।
  • Balanced class: Production fraud detection-এ ০.১% positive — Iris এই reality miss।
  • Numerical features only: categorical, text, datetime — সবই বাদ।
Iris-এ যা শিখলেন — workflow। কিন্তু production-এ আরও ১০টি challenge: data drift, label noise, missing pattern, feature engineering, cost-sensitive metric। L24-এ Titanic-এ এই reality।

ভাবনার প্রশ্ন

প্রতিটি প্রশ্ন নিজে কিছুক্ষণ ভাবুন — তারপর "→ উত্তর" চাপুন।

প্র ০১ Ronald Fisher-র Iris dataset ১৯৩৬-এর — এর ইতিহাস ও eugenics-এর সাথে fisher-র সম্পর্ক জানেন কি? ML community-তে এই dataset কেন এত deeply embedded? Replace করার সাম্প্রতিক চেষ্টা কী?

Iris dataset-এর "Hello World" status-এর পেছনে এক জটিল ইতিহাস। Statistical hero Ronald Fisher একই সঙ্গে eugenics movement-এ গভীরভাবে involved — ML community এই দ্বৈততা সম্প্রতি address করছে।

ইতিহাস:

  • Edgar Anderson (botanist) ১৯৩৫-এ Gaspé Peninsula-তে data collect — তিন species, ৫০-৫০-৫০।
  • Fisher ১৯৩৬-এ "The use of multiple measurements in taxonomic problems" paper-এ linear discriminant analysis demonstrate করতে use করেন।
  • Annals of Eugenics journal-এ publish — সেই সময়ে statistical journal এই নাম-এ পরিচিত।
  • UCI ML Repository (১৯৮৮) থেকে digital availability — তখন থেকে ML standard।

Fisher-র দ্বৈত legacy:

  • Statistics-এ অসাধারণ অবদান — ANOVA, maximum likelihood, experimental design।
  • একই সাথে — Eugenics Society-র president (১৯৪৭-৪৯), forced sterilization advocate, scientific racism-এ involved।
  • Cambridge University ২০২০-এ Fisher-এর stained glass window সরিয়েছে।
  • Royal Statistical Society "Fisher Memorial Lecture" নাম পরিবর্তন।

কেন Iris এত embedded:

  • ৪ feature, ৩ class, ১৫০ row — pedagogically অসাধারণ।
  • Linearly almost-separable — beginner-এর জন্য encouraging।
  • ৮০ বছরের tutorial, paper, textbook reference — switch cost বিশাল।
  • scikit-learn, R, MATLAB — সব built-in।
  • Reproducibility — ২০২৬-এও একই ১৫০ row।

ML community-র সাম্প্রতিক alternative:

  • Penguins dataset (২০২০): Allison Horst-এর তৈরি। Palmer Station Antarctica-র adelie/gentoo/chinstrap penguin। Iris-এর pedagogical replacement — community embracing।
  • Wine, Breast Cancer, Digits: sklearn-এ আগে থেকেই — Iris-এর alternative।
  • OpenML benchmark: ৫০০+ tabular dataset, modern, diverse।
  • HuggingFace Datasets Hub: ML community-চালিত dataset host।

সিদ্ধান্ত আমার নিজের teaching-এ:

  • Iris-র history acknowledge করুন — ছাত্রদের জানান।
  • Penguins-এ shift — same workflow, alternative ethics।
  • Bangladesh-specific data — চাল, পাট, fish species — local relevance।

বৃহত্তর পাঠ:

  • Dataset = neutral data নয়। Collection context, history, bias — সব encode।
  • Tool-এর creator-র legacy critically দেখা — replace করা না, একই সাথে অবদান + সমালোচনা।
  • Modern alternatives চয়ন — pedagogically equivalent, ethically cleaner।

মূল উপলব্ধি: Iris ML-এর "টেস্টিং ground" থাকবে কারণ pedagogically অসাধারণ। কিন্তু এর history আজ আমরা আর ignore করি না। Penguins, Wine — equally good replacement। Tool ব্যবহার করি, কিন্তু blind reverence-এ না — সেটাই mature scientific practice।

প্র ০২ EDA-তে কত সময় দেবেন? ৮০-২০ rule — ৮০% time data preparation, ২০% modeling — কেন বাস্তব? Cost-benefit analysis করুন।

২০১৬-র Forbes survey — data scientist-রা ৮০% সময় data prep ও cleaning-এ দেন, ২০% actual modeling-এ। ১০ বছর পরে — same numbers। Junior-রা rush করতে চায় modeling-এ, senior-রা EDA-তে গভীর। Why?

৮০-২০ rule-এর প্রমাণ:

  • CrowdFlower (২০১৬), Anaconda (২০২০), Kaggle (২০২২) — তিনটিতেই ~৭৫-৮৫% data prep।
  • Andrew Ng "Data-Centric AI" movement — model-centric থেকে data-centric switch।
  • Ng-এর claim: "Same model, ভাল data → ১০-৩০% accuracy boost।"

EDA-তে time spend-এর component:

  • Initial exploration (১৫%): shape, dtype, missing pattern।
  • Cleaning (৩০%): outlier, encoding error, type conversion, deduplication।
  • Feature engineering (২০%): domain knowledge inject — date থেকে weekday, address থেকে district।
  • Validation strategy (১০%): CV split design, leak audit, holdout planning।
  • Visualization (৫%): insight communication।

Cost-benefit analysis:

(ক) EDA skip-এর hidden cost:

  • Wrong feature pick → ৩ সপ্তাহ training waste।
  • Leak detection late → product launch-এর পরে ব্যর্থ।
  • Class imbalance miss → accuracy ৯৫% রিপোর্ট, real precision ৩০%।
  • Outlier ignore → loss function-এ extreme effect।
  • Wrong CV split → reported metric production-এ unreliable।

(খ) EDA-র concrete benefit:

  • Right algorithm choose — non-linear pattern চিনে tree, linear pattern চিনে logistic।
  • Feature engineering insight — "ratio better than absolute"।
  • Data quality issue early-catch।
  • Stakeholder communication — "data এই বলছে" — number-এ।

(গ) Diminishing returns:

  • প্রথম ৪ ঘণ্টা EDA — major issue catch, ৮০% value।
  • পরের ৪ ঘণ্টা — incremental insight, ১৫% value।
  • ৮ ঘণ্টার পরে — analysis paralysis, ৫% extra।
  • Time-box: small data ১ দিন, medium data ৩-৫ দিন, big data ১-২ সপ্তাহ initial; iterative পরে।

EDA framework — efficient ব্যবহারের জন্য:

  1. Lightning round (৩০ minute): shape, dtype, missing, head, value_counts।
  2. Hypothesis generation (১ ঘণ্টা): domain expert-এর সাথে — "এই data কী বলছে?"
  3. Targeted plotting (২ ঘণ্টা): hypothesis test — pairplot, boxplot।
  4. Cleaning sprint (১ দিন): identified issue address।
  5. Baseline model (২ ঘণ্টা): simplest possible — default features।
  6. Iteration: baseline failure mode → আরো EDA → improve।

Tool acceleration:

  • pandas-profiling / ydata-profiling: এক ক্লিকে full report।
  • sweetviz: train vs test EDA।
  • D-Tale, lux: interactive EDA UI।
  • great_expectations: data quality check automate।

কখন EDA shortcut নেওয়া যায়:

  • Same dataset আগে কাজ করেছেন।
  • Pretrained pipeline — তবু validation EDA রাখুন।
  • Quick prototype — known data ও clear question।

মূল উপলব্ধি: EDA কোনো optional step না — production ML-এর foundation। Junior-রা time waste মনে করে; senior-রা insurance। ৮০-২০ rule একটা signal: data-ই ML-এর majority। যিনি ভাল EDA করেন — তিনি ভাল ML engineer। Tool-এ shortcut নেই, discipline আছে।

প্র ০৩ Iris-এ ৯৭% accuracy পেলেন। Production-এ এই number reliable? Test set leakage, dataset shift, label noise — তিন threat কীভাবে চিনবেন?

Notebook-এ ৯৭% accuracy দেখে celebrate করা — junior-র সবচেয়ে সাধারণ ভুল। Production-এ সেই model ৬০-৭০%-এ নেমে যাওয়া স্বাভাবিক। তিন major threat — কেউ-ই সরাসরি দেখা যায় না।

(১) Test set leakage — সবচেয়ে subtle:

  • Preprocessing leak: scaler/imputer পুরো data-তে fit। (L20-এ আলোচিত)
  • Group leak: same patient train+test-এ। Solution: GroupKFold।
  • Time leak: future data train-এ। Solution: TimeSeriesSplit।
  • Duplicate leak: exact বা near-duplicate। Solution: dedup।
  • Iris-এ: ১-৩টি duplicate row আছে — minor কিন্তু থাকে।
  • Detect: "too good" accuracy, feature importance unrealistic, holdout vs CV mismatch।

(২) Dataset shift — production-এ data বদলায়:

তিন ধরনের shift:

  • Covariate shift: P(X) বদলায়। যেমন Iris model-কে Bangladesh-এর fern flower দিলে — feature distribution আলাদা।
  • Label shift: P(Y) বদলায়। COVID-এর আগে/পরে hospital admission rate ভিন্ন।
  • Concept drift: P(Y|X) বদলায়। Spam-এর pattern বছর-বছর evolve।

Detect ও mitigate:

  • Production data distribution monitor — KS test, PSI (Population Stability Index)।
  • Feature drift dashboard — Evidently AI, Arize, WhyLabs।
  • Periodic retraining schedule।
  • Adversarial validation — train-test classifier; AUC ≈ ০.৫ মানে similar distribution।

(৩) Label noise — silent killer:

  • Iris-এ label-error প্রায় ০ (botanist-এর verified)। কিন্তু production-এ — ১-২০% label error সাধারণ।
  • Crowdsourced label (MTurk) — ৫-১০% noise।
  • Annotator disagreement (medical image) — ১৫%।
  • Self-reported label (user feedback) — ২০%+।

Effect:

  • Test accuracy ceiling — অন্ততপক্ষে noise rate-এর সমান error থাকবে।
  • Model "noise model" learn করতে পারে — generalization হারায়।
  • Reported accuracy artificially low (true label ৯৮%, label-noise ৫%, observed ৯৩%)।

Detect ও mitigate:

  • cleanlab library: confident learning — sklearn model দিয়ে label issue automatically flag।
  • Cross-validation predictions: highest-loss example দেখুন — অনেক mislabel সেখানে।
  • Inter-annotator agreement: Cohen's kappa, Fleiss' kappa।
  • Label confidence in training: robust loss (Mean Absolute Error vs cross-entropy)।
  • Active relabeling: uncertain example human-relabel।

Iris-specific reality check:

  • Iris-এ none of these threats serious — তাই pedagogical।
  • Real Bangladesh flower classification করতে গেলে — সব তিনটি threat।
  • Iris model-কে প্রকৃত jungle photo দিলে — accuracy ১৫-২০% (covariate + concept shift)।

Production accuracy projection:

notebook_accuracy = 0.97
leakage_correction = 0.95   # leak থাকলে কতটা inflated
shift_correction   = 0.85   # production data shift-এ
noise_correction   = 0.95   # label noise

production_estimate = (
    notebook_accuracy *
    leakage_correction *
    shift_correction *
    noise_correction
)
# ~0.74 — অনেক বেশি realistic

মূল উপলব্ধি: Notebook accuracy = ceiling, production = reality। তিন threat (leak, shift, noise) — model বদলায় না, deploy কন্টেক্সট বদলায়। Mature ML engineer ৯৭% দেখে আত্মতৃপ্তি না, suspicion পায়। Holdout, monitoring, robust loss — ML production-এর সত্যিকার craftsmanship।

প্র ০৪ Bangladesh-এর কোন real-world dataset-এ EDA practice করা যায়? Government data, Kaggle, BB, BBS — কোথায় খুঁজবেন? Local data দিয়ে শেখার সুবিধা কী?

Iris, Titanic, Penguins — pedagogically অসাধারণ কিন্তু culturally distant। Bangladesh-এর data-তে কাজ করলে — domain intuition + technical skill একসাথে। Local context তো বুঝতে পারেন; data-র অর্থ করতে domain expert হতে হবে না।

(১) সরকারি public dataset:

  • Bangladesh Bureau of Statistics (BBS): bbs.gov.bd। HIES (Household Income and Expenditure Survey), Population Census, Labour Force Survey — exhaustive। PDF থেকে scrape কঠিন কিন্তু value বিশাল।
  • Bangladesh Bank: bb.org.bd। Monetary policy, banking, exchange rate time-series।
  • Open Data Portal (a2i): data.gov.bd। ৫০০+ dataset — health, education, agriculture।
  • Election Commission: constituency-wise voting data।
  • BMD (Meteorology): historical weather, cyclone track।

(২) Kaggle Bangladesh datasets:

  • "Bangladesh house price" — Dhaka real estate listings।
  • "BD Stock Market" — DSE daily data।
  • "Bangladesh COVID-19 data" — district-wise daily case।
  • "Bangla News" — text classification।
  • "Bengali handwritten digits" — OCR project।
  • Search: kaggle.com → "bangladesh"।

(৩) Academic / research data:

  • BRAC Research and Evaluation Division: microfinance, education impact studies।
  • icddr,b: health epidemiology — open dataset কিছু।
  • BUET, DU, BRAC University: CSE final-year project repository।
  • Bangla NLP corpora: BNLPC, csebuetnlp/banglabert dataset।

(৪) Self-collected scraping:

  • Daraz product listings — price prediction।
  • Pathao/Foodpanda — restaurant rating, delivery time।
  • Bikroy.com — used car/property।
  • Bangla newspaper headlines — sentiment, topic modeling।
  • YouTube Bangla comments — toxicity detection।
  • Caveat: ToS check, robots.txt respect, personal data avoid।

Local data দিয়ে শেখার সুবিধা:

  • Domain intuition built-in: "১২০০ টাকা/sqft Dhanmondi-তে undervalued" — instantly বুঝে। Iris petal-এ এই intuition নেই।
  • Real preprocessing challenge: Bangla text encoding, mixed Bangla-English, Bengali date format।
  • Career relevance: Bangladesh employer-এর জন্য portfolio।
  • Social impact: health, education, agriculture — meaningful problem।
  • Less competition: ছোট community → contribute করার সুযোগ।

সাধারণ challenges:

  • Quality: government data PDF, inconsistent format, missing year।
  • Bangla text: Unicode normalization, OCR error।
  • Privacy law: Data Protection Act (২০২৩) — personal data carefully।
  • Annotation: labeled data scarce — তৈরি করতে effort।

একটি practical project ধারণা:

  • BBS labour force survey → district-wise unemployment prediction।
  • BB exchange rate + global indicator → BDT volatility forecast।
  • Daraz product + review → category classifier।
  • Pathao trip time → ETA prediction by district।
  • Bangla news + topic → unsupervised cluster।

Community ও sharing:

  • Bangladesh AI Community — Facebook group, ৫০K+ member।
  • BD AI Olympiad — competition platform।
  • HuggingFace Hub-এ Bangla model upload — global visibility।
  • GitHub portfolio — Bengali README দিয়ে দেশীয় relevance।

মূল উপলব্ধি: Iris থেকে BBS — pedagogy থেকে impact। Tutorial dataset দিয়ে syntax শিখুন, local data দিয়ে judgment। বাংলাদেশের AI ecosystem গড়তে — local data-তে কাজ করা ML practitioner-দের responsibility। ছোট কাজও — local context-এ — বিশ্বের কাজের চেয়ে বেশি impactful হতে পারে।

অনুশীলন

  1. Penguins দিয়ে EDA: Iris-এর বদলে sns.load_dataset("penguins") দিয়ে একই workflow চালান। Missing handle করুন, class balance check, pairplot করুন।
    import seaborn as sns
    import matplotlib.pyplot as plt
    
    peng = sns.load_dataset("penguins")
    print("Shape:", peng.shape)
    print("Missing:", peng.isna().sum().sum())
    print("Class balance:")
    print(peng["species"].value_counts())
    
    # Missing drop (ছোট fraction)
    peng = peng.dropna()
    
    sns.pairplot(peng, hue="species", height=2.0, corner=True)
    plt.suptitle("Penguins — pairwise structure", y=1.02)
    plt.show()
  2. Discriminative feature: Iris-এ প্রতিটি feature-এর কোন class-এ mean সবচেয়ে আলাদা — groupby দিয়ে দেখান। সবচেয়ে discriminative feature কোনটি?
    import seaborn as sns
    iris = sns.load_dataset("iris")
    
    print(iris.groupby("species").mean(numeric_only=True).round(2))
    
    # spread মাপ — std of class-means / overall std
    ratios = (iris.groupby("species").mean(numeric_only=True).std() /
              iris.select_dtypes("number").std()).sort_values(ascending=False)
    print("\nDiscriminative ratio (higher = better):")
    print(ratios.round(2))

    petal_length ও petal_width সর্বোচ্চ — class-mean differ অনেক, যা শুরুর insight-কেই reinforce।

  3. Outlier check: Iris-এর কোনো column-এ outlier আছে কি? IQR method দিয়ে চেক করুন।
    import seaborn as sns
    import numpy as np
    iris = sns.load_dataset("iris")
    
    for col in iris.select_dtypes("number").columns:
        q1, q3 = iris[col].quantile([0.25, 0.75])
        iqr = q3 - q1
        low, high = q1 - 1.5 * iqr, q3 + 1.5 * iqr
        outliers = iris[(iris[col] < low) | (iris[col] > high)]
        print(f"{col}: {len(outliers)} outlier(s)")

    sepal_width-এ ৪টি outlier — borderline। Removable নয়, বরং species-context-এ বুঝতে হবে।

আরও পড়ুন · ABCL TECH-এ আপনার পরবর্তী পদক্ষেপ

কোড রানার কাজ না করলে? ব্রাউজারে কাজ না করলে Google Colab ব্যবহার করুন — Iris ও Penguins দু'টোই Seaborn-এ pre-installed।
পূর্ববর্তী পাঠ
পাঠ ২০ · scikit-learn-এর সাথে পরিচয়