Visualizing Regression Plots
Learn how to harness Plotly figures to assist in visualizing and analysing regression models in Python.
Scatter plot smoothing
Scatter plot smoothing is a statistical technique used to gain an understanding of the general patterns in the data by creating a curve with a smoothed estimate of the relationship between two variables, x and y. It is also particularly useful for assessing bivariate outliers and influential observations that may affect the relationship between the variables.
This is a
-
GNP.deflator
: GNP implicit price deflator (1954=100) -
GNP
: Gross National Product -
Unemployed
: Number of unemployed -
Armed.Forces
: Number of people in the armed forces -
Population
: ‘noninstitutionalized’ population ≥ 14 years of age -
Year
: The year (time) -
Employed
: Number of people employed
Note: This dataset is often used to demonstrate how regressing
Employed
on the remaining variables causes multicollinearity.
# Import librariesimport pandas as pdimport numpy as np# Import datasetslongley = pd.read_csv('/usr/local/csvfiles/longley.csv')print(longley.head())
Linear regression
Plotly Express allows us to fit a linear regression to a dataset with an x
and y
variable. We do this by placing a trendline="ols"
argument to specify that we wish to use an ordinary least squares regression model. We can set the color of the line using trendline_color_override
. By hovering over the trend line, we gain an insight into the slope, intercept, coefficient of determination (), and prediction ...