Il contratto di fit e predict
L'API condivisa da ogni estimator.
Il contratto di fit e predict è 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.
Meet the Estimator
In scikit-learn, every model is an estimator: one object you create, teach, and then ask for answers. Same shape, every time. 🤖
Two Verbs to Remember
The whole library rests on two methods: fit to learn from data, and predict to use what it learned. Master these and you can use almost any model.
fit Means Learn
Calling fit shows the model your examples so it can find patterns. Nothing is predicted yet, the model is simply studying the data.
model.fit(X, y)predict Means Answer
Once trained, predict takes fresh inputs and returns the model's best guesses. This is where the learning finally pays off.
predictions = model.predict(X_new)One Consistent Contract
This fit-then-predict pattern is a contract every estimator honors. Swap a tree for a linear model and your code barely changes.
Create Before You Train
You always build the estimator first, often with settings, before any data touches it. That blank model is ready to learn.
from sklearn.linear_model import LinearRegression
model = LinearRegression()Order Always Matters
You must fit before you predict. Asking an untrained model for answers raises an error, since it has learned nothing yet.
fit Returns the Model
The fit call also returns the model itself, so you can chain steps in one line when you want compact, readable code.
model = LinearRegression().fit(X, y)Learned State Lives Inside
After fitting, the model stores what it learned in attributes ending with an underscore, like coef_. They appear only once training is done.
model.coef_Same API, Many Models
Because the API is shared, you can try several models by changing one line. The fit and predict calls stay identical.
from sklearn.tree import DecisionTreeRegressor
model = DecisionTreeRegressor()Why This Design Wins
One predictable interface means less to memorize and faster experiments. You focus on the problem, not on each library's quirks.
Quick Check
Let's lock in the core contract every estimator follows.
Recap
Every estimator follows one contract: create it, call fit to learn, then predict to answer. One pattern unlocks the whole library. 🎯
Domande Frequenti
La lezione «Il contratto di fit e predict» è gratuita?
Sì — il testo completo di «Il contratto di fit e predict» è 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 «Il contratto di fit e predict»?
L'API condivisa da ogni estimator. 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 «Il contratto di fit e predict»?
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
- Il contratto di fit e predict
- Feature X e target y
- Addestrare una regressione lineare
- Valutare il primo modello