make_regression() function in sklearn with Python

In this tutorial, we will learn about make_regression() function in sklearn with Python. So, before starting let us see what we are going to do exactly.

There are many datasets available such as for classification and regression problems. Here our task is to generate one of such dataset i.e. linear regression dataset. Before jumping to the main topic let us have a brief introduction to basic terminologies.

Scikit learn

It is one of the most popular Machine learning library. Using it we can write any Machine learning code in a couple of lines. You can learn more about it hereĀ How to Make Predictions with scikit-learn in Python

make_regression() function in scikit learn

It is a function in sklearn_datasetsĀ which is used to generate our dataset for the regression problem. It is described in the code in python below.

Code in Python programming language

We will write this code in google colab.

from sklearn.datasets import make_regression
from matplotlib import pyplot
X_test, y_test = make_regression(n_samples=150, n_features=1, noise=0.2)


make_regression() function in sklearn with Python

Initially, we imported the required library. After that, we made a dataset using make_regression(). Then using matplotlib we plotted our plot as you can see in the above figure. Further, one thing to notice here is that we have made a dataset of 150 entries and with noise 0. However, we can change these values as I have demonstrated below.

make_regression() function in sklearn with Python

make_regression() function in sklearn with Python

For example, In the above two figures, you can observe that as the noise increased from 10 to 50 our dataset become more scattered. That’s it! We have successfully generated our dataset.

One response to “make_regression() function in sklearn with Python”

  1. LIMA says:

    x, y = make_regression(n_samples=100, n_features=1, n_informative=1, n_targets=1, noise=20, random_state=13)
    I cannot understand these parameters

Leave a Reply

Your email address will not be published. Required fields are marked *