0Pricing
Data Science Academy · Lezione

Precision, recall e F1

Bilanciare i diversi tipi di errore.

Precision, recall e F1 è una lezione Data Science Academy gratuita su CoddyKit. Questa è la lezione 3 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.

Why Accuracy Falls Short

When one class is rare, accuracy can look great while the model misses everything that matters. You need sharper metrics like precision and recall. 🎯

Precision Defined

Precision asks: of all the cases I flagged as positive, how many were truly positive? It measures how trustworthy a yes really is.

precision = TP / (TP + FP)

When Precision Matters

High precision matters when false alarms are costly, like marking a real email as spam. You want every flag to be correct.

Recall Defined

Recall asks: of all the truly positive cases, how many did I catch? It measures how good the model is at not missing things.

recall = TP / (TP + FN)

When Recall Matters

High recall matters when misses are dangerous, like screening for a disease. Catching every real case outweighs a few false alarms.

The Tug of War

Precision and recall usually pull against each other. Flag more cases and you catch more but raise false alarms. It is a trade-off.

Enter the F1 Score

The F1 score blends precision and recall into one number using their harmonic mean, rewarding models that balance both well.

f1 = 2 * (precision * recall) / (precision + recall)

Why Harmonic Mean

The F1 uses a harmonic mean so a low score on either side drags it down. You cannot fake it by acing just one metric.

Get Them in One Call

You do not compute these by hand. The classification report prints precision, recall, and F1 for every class at once.

from sklearn.metrics import classification_report
print(classification_report(y_true, y_pred))

Pick the Metric to Optimize

Let the problem decide. Optimize recall when misses hurt, precision when false alarms hurt, and F1 when you need a balance.

Watch the Averaging

With many classes, choose how to average. Macro treats classes equally, weighted accounts for class size. The choice changes the story.

f1_score(y_true, y_pred, average='macro')

Quick Check

Let's make sure precision and recall stay straight in your mind.

Recap

Precision trusts your yes, recall catches the positives, and F1 balances both. Let the cost of each mistake guide your choice. 🎯

Domande Frequenti

La lezione «Precision, recall e F1» è gratuita?

Sì — il testo completo di «Precision, recall e F1» è 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 «Precision, recall e F1»?

Bilanciare i diversi tipi di errore. 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 3 di 4.

Quanto tempo richiede la lezione «Precision, recall e F1»?

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. Metriche di regressione: MAE, MSE, R2
  2. Decodificare la matrice di confusione
  3. Precision, recall e F1
  4. ROC, AUC e soglie
← Torna a Data Science Academy