Lesson Introduction

In this lesson, we explore how to make predictions using a trained machine learning model and visualize the results. Understanding predictions and visualizations helps interpret model performance and make informed decisions.

Our goal is to build on the trained linear regression model from the last lesson, use it to predict, and visualize these predictions against actual data. This will provide a clear picture of your model's performance.

Making Predictions with a Trained Model: Understanding

First, let's recap. In the last lesson, we trained a linear regression model to understand the relationship between the area of a house and its price using synthetic data. We will use the same code snippet for generating the data as we used in the previous lesson:

Now, imagine you have new data, like areas of new houses, and want to predict their prices using your trained model. This is where the predict method from Scikit-Learn comes into play.

The predict method takes input data and generates the predicted output based on the model.

We'll start by importing essential libraries, including NumPy, Pandas, Matplotlib, and Scikit-Learn. We'll use the same data generation script as in the previous lesson.

Making Predictions with a Trained Model: Application

First, we initialize and train the model using our data.

Then, let's make predictions with our trained model. Suppose you want to predict prices for houses with areas of 200 and 3500 square feet.

In real life, you might need to predict prices for several new houses, not just two.

Visualizing Prediction Results: Part 1

Visualizing your predictions against actual data helps to understand your model's performance. We'll use Matplotlib to create a scatter plot for the actual data and a line plot for predicted data.

A scatter plot is ideal for visualizing individual data points, perfect for plotting actual house prices against their areas.

Visualizing Prediction Results: Part 2

Next, we'll draw a line plot to visualize the predictions. This line shows how the predicted prices vary with house areas.

In this plot:

  • Blue points represent actual data.
  • The red line represents the model's predictions.

The closer the points are to the red line, the better your model's predictions. In this case, we can see that the line and the points are well-aligned. In reality, data could me much noisier.

Lesson Summary

Congratulations! You've learned how to make predictions using a trained machine-learning model and visualize results. In this lesson, we covered:

  • Generating and preparing data.
  • Using the predict method to generate new predictions.
  • Visualizing actual data and predicted results using Matplotlib.

Visualizing predictions helps you understand and evaluate your model's performance. Good models have predicted values close to the actual values, making the plot look smoother.

Now, it's time to use what you've learned in practice. In the practice session, you'll generate your predictions and visualize them. This hands-on experience will reinforce your skills and make you more comfortable with making predictions and visualizing results. Happy coding!

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal