Checking linearity for a linear regression model?
I like GAM (Generalised additive model) with regression splines:
# Load data
library(ISLR)
a = Auto

# Run GAM with splines
library(gam)
g = gam(mpg~s(displacement,5)+s(horsepower,5),data=a)
plot(g, se=T)


The result (plot) shows you that displacement can be well approximated by a linear function for lower values (&lt; 250 or so). However, there is a &quot;kink&quot; at about 250, so that overall, a linear approximation would not be very good here.
See ISL, Chapter 7 for more details. There are also Labs for Python and R where you can see code details.
Also see this example in R with simulated data for more details.
Alternatively, look at a Q–Q plot after regression, e.g. in R:
l = lm(mpg~s(displacement,5)+s(horsepower,5),data=a)
plot(l)