0Pricing
Data Science Academy · Lezione

Metriche di regressione: MAE, MSE, R2

Misurare l'errore delle previsioni numeriche.

Metriche di regressione: MAE, MSE, R2 è 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.

Why Measure Error

When a model predicts numbers, you need one honest score for how far off it is. That score is an error metric, your truth-teller. 📏

The Residual Idea

Start with the residual: the gap between the true value and the predicted one. Every regression metric is just a way to summarize these gaps.

residual = y_true - y_pred

Mean Absolute Error

MAE takes the size of each error, ignores the sign, and averages them. It tells you the typical miss in the same units as your target.

from sklearn.metrics import mean_absolute_error
mean_absolute_error(y_true, y_pred)

MAE Is Easy to Explain

Because MAE stays in real units, you can say the model is off by about 5 dollars on average. Stakeholders love that plain reading.

Mean Squared Error

MSE squares each error before averaging. Squaring punishes big misses much harder, so a few large errors dominate the score.

from sklearn.metrics import mean_squared_error
mean_squared_error(y_true, y_pred)

Squaring Changes the Units

One catch: MSE is in squared units, so dollars become squared dollars. The number is hard to interpret on its own.

Root Mean Squared Error

Take the square root of MSE to get RMSE, back in normal units. It keeps the heavy penalty on big errors but reads cleanly.

rmse = mean_squared_error(y_true, y_pred) ** 0.5

MAE vs RMSE

Choose MAE when every error matters equally, and RMSE when large mistakes are especially costly and you want them penalized more.

The R-Squared Score

R2 asks a different question: what fraction of the variation in the target your model explains. Higher means a better fit.

from sklearn.metrics import r2_score
r2_score(y_true, y_pred)

Reading R-Squared

An R2 of 1.0 is perfect, 0.0 is no better than guessing the mean. It can even go negative when a model fits worse than that.

Use Them Together

No single number tells the whole story. Pair an error metric like RMSE with R2 to see both the typical miss and the overall fit.

Quick Check

Let's pin down what each regression metric really measures.

Recap

Use MAE for plain average error, RMSE to punish big misses, and R2 for fraction of variance explained. Read them together. 🎯

Domande Frequenti

La lezione «Metriche di regressione: MAE, MSE, R2» è gratuita?

Sì — il testo completo di «Metriche di regressione: MAE, MSE, R2» è 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 «Metriche di regressione: MAE, MSE, R2»?

Misurare l'errore delle previsioni numeriche. 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 «Metriche di regressione: MAE, MSE, R2»?

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