Skip to main content
Colin Jaffe/2 min read

Training and Testing Linear Regression Models

ML Project Workflow

1

Define the Problem

What outcome are you predicting and why?

2

Prepare the Data

Clean, normalize, encode categoricals, split into train/test.

3

Train Models

Start simple — logistic regression baselines often surprise.

4

Evaluate & Iterate

Confusion matrix, ROC, F1 — pick metrics that match the problem.

Master Machine Learning at Noble Desktop

Noble Desktop's Python Machine Learning Bootcamp covers scikit-learn, Keras, neural networks, and applied ML.

This lesson is a preview from our Data Science & AI Certificate Online (includes software) and Python Certification Online (includes software & exam). Enroll in a course for detailed lessons, live instructor support, and project-based training.

Train the linear regression model using X train and Y train data. Watch this tutorial to learn the key concepts and techniques.

Let's train the model. We created this model and named it 'model', and now it has a fit method on it. That method fits the data and trains the model on it.

We get back a trained model. It will take our training data as its inputs, and that's the X train and the Y train. Remember, it needs to know the answer as well as the inputs, the features and the label that corresponds to those features.

This allows the model to classify data such as identifying a cat or a dog. Or, for example, the model might learn that 5 minus 3 equals 2 and 7 minus 4 equals 3, hoping it will detect patterns and relationships. The model needs both the question (input) and the answer (label) to understand the concept.

We provide it with the data and allow it to train on it. It's that simple.

We simply use model.fit. It's straightforward, not necessarily easy. Give it the X train data and the Y train data.

It will evaluate as a linear regression model, as shown here. Now that the model is trained, and it was done quickly, we can begin testing the model to see how well it works.