Plotly Linear Regression

In this Plotly tutorial, you will learn how to plot linear regression in Python. You have to use the parameter trendline="ols" for linear regression.

# Import Plotly Module
import plotly.express as px

# Import Dataset
dataset = px.data.gapminder().query("continent=='Oceania'")

# Linear Regression
plot = px.scatter(dataset, x="gdpPercap", y="lifeExp", trendline="ols")

# Show the Plot
plot.show()

Output:

Plotly Linear Regression

Free learning resources: AiHintsCodeAllow

Leave a Comment

Your email address will not be published.