El contrato de fit y predict
La API que comparten todos los estimadores.
El contrato de fit y predict es una lección gratuita de Data Science Academy en CoddyKit. Esta es la lección 1 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de Data Science Academy, y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de Data Science Academy incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
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. 🎯
Preguntas frecuentes
¿La lección «El contrato de fit y predict» es gratis?
Sí — el texto completo de «El contrato de fit y predict» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de Data Science Academy, actualiza a CoddyKit PRO. El curso de Data Science Academy incluye 4 lecciones en total.
¿Qué aprenderé en «El contrato de fit y predict»?
La API que comparten todos los estimadores. Practicas Data Science Academy con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar Data Science Academy?
No se requiere experiencia previa. Data Science Academy en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 1 de 4.
¿Cuánto tiempo toma la lección «El contrato de fit y predict»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de Data Science Academy?
Sí. Cada lección de Data Science Academy incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- El contrato de fit y predict
- Características X y objetivo y
- Entrenar una regresión lineal
- Evaluar su primer modelo