0Pricing
Data Science Academy · Lezione

Perché l'accuratezza inganna con dati sbilanciati

La trappola della classe rara.

Perché l'accuratezza inganna con dati sbilanciati è una lezione Data Science Academy gratuita su CoddyKit. Questa è la lezione 1 di 4. Puoi leggere la lezione completa qui gratuitamente — poi esercitati direttamente nel browser con un editor di codice integrato e un tutor IA disponibile 24/7. Fa parte del percorso di apprendimento Data Science Academy, e i tuoi progressi si sincronizzano tra il web e l'app CoddyKit. Il corso Data Science Academy include 4 lezioni in totale.

Parti di questa lezione non sono ancora state tradotte e vengono mostrate in inglese.

The Comfortable Lie

Accuracy feels like the obvious score: how many predictions you got right. On balanced data it works fine, but imbalance quietly breaks it.

What Imbalance Means

A dataset is imbalanced when one class is far rarer than the others. Think fraud, disease, or churn: the interesting event is the rare one.

The 99% Trap

Imagine 99 normal transactions for every 1 fraud. A model that screams normal every single time scores a glorious 99% accuracy. ⚠️

Yet It Caught Nothing

That 99% model never flagged a single fraud. The number looks elite, but the model is useless for the exact job you hired it to do.

Accuracy Hides the Rare Class

Accuracy averages over all rows, so the huge majority drowns out the tiny minority. The rare class can be a total failure and barely move the score.

The Baseline You Must Beat

Always compare against the majority-class baseline: just predict the most common label. If your model cannot beat it, it learned nothing useful.

A Quick Reality Check

Before celebrating, ask one thing: what fraction of rows is the majority class? That number is the accuracy a lazy model gets for free.

See It With value_counts

One line reveals how lopsided your labels are. If one value dwarfs the rest, accuracy alone will mislead you.

counts = y.value_counts(normalize=True)
print(counts)  # share of each class

Where the Cost Really Lives

Missing the rare class usually hurts most: an undetected tumor or fraud is costly. Accuracy treats every mistake as equal, but reality does not.

Look Past One Number

The fix is not a magic metric yet, it is a mindset. Stop trusting a single number and start asking how the minority class actually did.

Set Up for Better Metrics

Soon you will meet precision, recall, and PR curves built for rare events. First, internalize why accuracy earned your distrust here.

Quick Check

Why can accuracy mislead on imbalanced data?

Recap

On imbalance, accuracy flatters lazy models that ignore the rare class. Beat the majority baseline and judge how the minority class truly did. 🎯

Domande Frequenti

La lezione «Perché l'accuratezza inganna con dati sbilanciati» è gratuita?

Sì — il testo completo di «Perché l'accuratezza inganna con dati sbilanciati» è gratuito qui sul web. Per esercitarvi in modo interattivo (un editor di codice integrato e un tutor IA 24/7) e sbloccare il resto del corso Data Science Academy, passa a CoddyKit PRO. Il corso Data Science Academy include 4 lezioni in totale.

Cosa imparerò in «Perché l'accuratezza inganna con dati sbilanciati»?

La trappola della classe rara. Eserciti Data Science Academy con codice pratico che esegui direttamente nel browser, e un tutor IA 24/7 risponde alle tue domande mentre lavori sulla lezione.

Ho bisogno di esperienza per iniziare Data Science Academy?

Non è richiesta alcuna esperienza precedente. Data Science Academy su CoddyKit è strutturato per principianti e studenti avanzati, quindi puoi iniziare da qui o dall'inizio e procedere al tuo ritmo. Questa è la lezione 1 di 4.

Quanto tempo richiede la lezione «Perché l'accuratezza inganna con dati sbilanciati»?

La maggior parte delle lezioni CoddyKit richiede circa 5–10 minuti. Ogni lezione è breve e interattiva, quindi fai progressi costanti e riprendi esattamente da dove hai lasciato su web e app.

Posso scrivere ed eseguire codice in questa lezione Data Science Academy?

Sì. Ogni lezione Data Science Academy include un editor di codice integrato, quindi scrivi ed esegui codice reale direttamente nel tuo browser e ricevi feedback istantaneo dall'IA — nessuna configurazione locale necessaria.

Tutte le lezioni di questo corso

  1. Perché l'accuratezza inganna con dati sbilanciati
  2. Ricampionamento: SMOTE e undersampling
  3. Pesi delle classi e soglie
  4. Scegliere le metriche per gli eventi rari
← Torna a Data Science Academy