0Pricing
Data Science Academy · Lezione

Addestrare una regressione lineare

Un esempio completo dall'inizio alla fine.

Addestrare una regressione lineare è 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.

A Line Through Data

Linear regression fits a straight-line relationship between your features and a numeric target. It is the classic first model for a reason. 📈

Import the Model

The estimator lives in the linear_model module. You import it once and reuse it for any regression task you meet.

from sklearn.linear_model import LinearRegression

Create an Instance

Build a fresh model by calling the class. This blank estimator holds default settings and has not seen any data yet.

model = LinearRegression()

Fit on Training Data

Now teach it with your features and target. During fit, the model finds the best line through your training points.

model.fit(X_train, y_train)

Read the Slope

Each feature gets a coefficient stored in coef_. It tells you how much the prediction moves when that feature rises by one.

model.coef_

Read the Intercept

The intercept is the prediction when every feature is zero. It anchors the line and is stored in intercept_ after fitting.

model.intercept_

Make Predictions

Hand new feature rows to predict and you get numeric estimates back, one per row, computed straight from the fitted line.

y_pred = model.predict(X_test)

The Equation Behind It

Under the hood, each prediction is just features times coefficients plus the intercept. Simple math, surprisingly powerful results.

One Feature or Many

The same call handles a single feature or dozens. With many inputs it fits a hyperplane, but your code stays exactly the same.

Linear Means a Straight Fit

Linear regression assumes a roughly straight relationship. If the pattern curves sharply, this model will underfit and miss it.

The Full Workflow

Import, create, fit, predict: four steps and you have a working regressor. This same rhythm repeats for every model you learn next.

Quick Check

Which attribute holds the per-feature weights after fitting?

Recap

You imported, created, fit, and predicted with a linear regression. Its coef_ and intercept_ even reveal what it learned. 🚀

Domande Frequenti

La lezione «Addestrare una regressione lineare» è gratuita?

Sì — il testo completo di «Addestrare una regressione lineare» è 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 «Addestrare una regressione lineare»?

Un esempio completo dall'inizio alla fine. 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 «Addestrare una regressione lineare»?

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. Il contratto di fit e predict
  2. Feature X e target y
  3. Addestrare una regressione lineare
  4. Valutare il primo modello
← Torna a Data Science Academy