0Pricing
Data Science Academy · Lezione

Ricampionamento: SMOTE e undersampling

Ribilanciare il training set.

Ricampionamento: SMOTE e undersampling è una lezione Data Science Academy gratuita su CoddyKit. Questa è la lezione 2 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.

Rebalance the Training Set

One way to help a model see the rare class is to resample: change how many examples of each class it trains on.

Two Directions to Balance

You can add more of the minority (oversample) or trim the majority (undersample). Both aim to even out the class counts.

Naive Oversampling

The simplest oversample just copies minority rows until counts match. It works, but those exact duplicates can make a model memorize them.

Enter SMOTE

SMOTE creates synthetic minority examples instead of copies. It invents new, plausible points between real minority neighbors.

How SMOTE Builds Points

SMOTE picks a minority row, finds a nearby minority neighbor, and places a fresh point somewhere on the line between them.

SMOTE in Code

The imbalanced-learn library makes SMOTE a two-line affair on your training features and labels.

from imblearn.over_sampling import SMOTE
X_res, y_res = SMOTE().fit_resample(X_train, y_train)

Undersampling the Majority

Undersampling drops majority rows until balance returns. It trains faster but throws away data, which can cost real signal.

When to Pick Which

Oversample when data is scarce and every row matters. Undersample when the majority is huge and you can spare some rows for speed.

The Cardinal Rule

Resample only the training set. Touch the test set and your scores become fantasy, since real data is never rebalanced for you.

Fit on Train Only

SMOTE must learn from training rows alone. Leaking test rows into resampling inflates results and quietly causes data leakage. ⚠️

Resampling Is Not a Cure-All

Balanced counts help, but they are not magic. Pair resampling with the right metrics and sometimes class weights for the best results.

Quick Check

What makes SMOTE different from plain oversampling?

Recap

Resampling balances the training set by oversampling (SMOTE makes synthetic rows) or undersampling. Never resample the test set. 🎯

Domande Frequenti

La lezione «Ricampionamento: SMOTE e undersampling» è gratuita?

Sì — il testo completo di «Ricampionamento: SMOTE e undersampling» è 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 «Ricampionamento: SMOTE e undersampling»?

Ribilanciare il training set. 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 2 di 4.

Quanto tempo richiede la lezione «Ricampionamento: SMOTE e undersampling»?

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