# How can non-linear data be fit to a model in Python?

PythonServer Side ProgrammingProgramming

We will be using the Seaborn library, that helps in visualizing data.When regression models are being built, multicollinearity is checked for. This is because we need to understand the correlation present between all different combinations of continuous variables. If multicollinearity exists between the variables, we have to make sure that it is removed from the data. The data in real world is usually non-linear.

We need to find mechanisms to fit such non-linear data to the model. We will be using Anscombe’s dataset to visualize this data. The ‘implot’ function is used with this non-linear data.

Here’s the example −

## Example

import pandas as pd
import seaborn as sb
from matplotlib import pyplot as plt
sb.lmplot(x="x", y="y", data=my_df.query("dataset == 'I'"))
plt.show()

## Explanation

• The required packages are imported.
• The input data is ‘anscombe’ which is loaded from the seaborn library.
• This data is stored in a dataframe.
• This data is visualized using the ‘implot’ function.
• Here, the dataframe is supplied as parameter.
• Also, the x and y values are specified.
• This data is displayed on the console.
Published on 11-Dec-2020 10:31:56