Seaborn Regression plots - Introduction



A statistical charting tool called Seaborn offers straightforward techniques for adding regression lines to your scatter diagrams and can read Pandas dataframes as well as other types of data formats. An excellent tool for examining links or trends in data is a scatter plot. But by including a regression line, those patterns can become more obvious.

In an effort to discover the scatter plot's points that fit together the best, the regression line is used.

Drawing regression plots with small data. We begin by importing the seaborn library

import seaborn as sns

We can draw a scatterplot for any dataset by using the below code snippet. Considering the following case, we are using the in-built titanic dataset in seaborn library and x,y parameters are passed to the scatterplot() method and a graph is obtained.

sns.scatterplot(data=titanic,x="age",y="fare")

The output is obtained as follows −

Regression plots

On observing the above plot, you will be able to understand the linear relationship but drawing a regression line makes it easier.

Seaborn Regression plots

The above figure shows the regression line drawn over the plot.

Since we have understood how regression lines help us, now we will see how to add regression lines to your plots. This can be done with the help of the regression plot methods in seaborn.

There are three different types of regression plots in seaborn.

S.No Method & Description
1

The regplot() method

seaborn.regplot() method is used to plot data and draw a linear regression model fit.

2

The lmplot() method

seaborn.lmplot() method is used to plot data and draw regression model fits across grids where multiple plots can be plotted.

3

The residplot() method

seaborn.residplot() method is used to plot residual data of a linear regression.

seaborn_function_reference.htm
Advertisements