0Pricing
Data Science Academy · Aula

O contrato de fit e predict

A API compartilhada por todo estimador.

O contrato de fit e predict é uma aula grátis de Data Science Academy no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Data Science Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Data Science Academy inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em 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. 🎯

Perguntas Frequentes

A aula “O contrato de fit e predict” é grátis?

Sim — o texto completo de “O contrato de fit e predict” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Data Science Academy, atualize para CoddyKit PRO. O curso de Data Science Academy inclui 4 aulas no total.

O que vou aprender em “O contrato de fit e predict”?

A API compartilhada por todo estimador. Você pratica Data Science Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Data Science Academy?

Nenhuma experiência prévia é necessária. Data Science Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.

Quanto tempo leva a aula “O contrato de fit e predict”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Data Science Academy?

Sim. Cada aula de Data Science Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. O contrato de fit e predict
  2. Recursos X e alvo y
  3. Treinar uma regressão linear
  4. Avaliar seu primeiro modelo
← Voltar para Data Science Academy