0Pricing
Data Science Academy · Lesson

The fit and predict Contract

The API shared by every estimator.

The fit and predict Contract is a free Data Science Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Data Science Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

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. 🎯

Frequently asked questions

Is the “The fit and predict Contract” lesson free?

Yes — the full text of “The fit and predict Contract” is free to read here on the web, and the Data Science Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Data Science Academy course, upgrade to CoddyKit PRO.

What will I learn in “The fit and predict Contract”?

The API shared by every estimator. You practise Data Science Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Data Science Academy?

No prior experience is required. Data Science Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “The fit and predict Contract” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Data Science Academy lesson?

Yes. Every Data Science Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The fit and predict Contract
  2. Features X and Target y
  3. Train a Linear Regression
  4. Score Your First Model
← Back to Data Science Academy