Why this matters
Regression and classification are the two everyday tasks of machine learning. A fintech estimating a safe loan size is doing regression; the same company deciding whether to approve the loan is doing classification. scikit learn, named in junior data science adverts, makes both possible in a few lines, and its pattern is the same for every model.
The scikit learn pattern
Every scikit learn model follows three steps:
- Create the model:
model = LinearRegression(). - Fit it to training data:
model.fit(X_train, y_train). - Predict on new data:
model.predict(X_test).
Learn this once and you can swap in dozens of other models with one changed line.
Regression with a baseline
Using the invented example farm data from earlier, with X holding rainfall and fertiliser and y holding yield in bags: