liveBook · Manning

Fit method

As explained in Grokking Machine Learning, Second Edition

An estimator operation that learns model parameters from supplied input features and target labels.

A fit method is the step where an estimator learns model parameters from supplied features and labels. Give it X, the input data, and y, the target values; it adjusts its model to the examples. section 3.27 section 5.21

The exact preparation depends on the data. Housing features may need missing-value removal, scaling, centering, and one-hot encoding; review text becomes word-count features before fitting. section 3.27 section 6.12

Common uses include:

  • Train a linear regression model with area as X and house price as y. section 3.27
  • Train a perceptron classifier with features and labels, then predict the class of each point. section 5.21
  • Build a review vocabulary with CountVectorizer.fit_transform, then fit logistic regression to positive and negative sentiments. section 6.12
X = data[‘Area’]
y = data[‘Price’]
simple_model = LinearRegression()
simple_model.fit(X, y)

See the compact pattern: select feature and label columns, create an estimator, and call its fit method. section 3.27

How Grokking Machine Learning, Second Edition covers it

How deep it goes
Shows the call and resulting weights or predictions, but does not explain the optimization internals.
Examples
Uses housing prices, IMDB reviews, word-count vectors, and a small perceptron classification dataset.
What it assumes
Assumes basic features and labels, while demonstrating their preparation from tables, text, and categorical columns.
What you can do after
Apply it via scikit-learn to train regression and classification estimators, inspect learned parameters, and make predictions.
How it connects
Connects preprocessing with linear regression, logistic regression, perceptrons, features, labels, and prediction.

Also explained in

Compare how 3 books explain fit method →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Machine Learning, Second Edition. The section links point to the parts of the book it draws on.