data
library('ISLR')
## Warning: package 'ISLR' was built under R version 3.5.2
library(splines)
mpg = Auto$mpg
accel = Auto$acceleration
cyl = Auto$cylinders
horse = Auto$horsepower
year = Auto$year
dis = Auto$displacement
x = displacement and y = mpg
y = mpg
x = dis
x0 = 250
poly2 = lm(y ~ poly(x, 2), data = Auto)
cubic = lm(y ~ bs(x, knots = c(105, 151, 275.8)), data = Auto)
natty = lm(y ~ ns(x, knots = c(105, 151, 275.8)), data = Auto)
smooth = smooth.spline(x, y, df = 10)
predict(poly2)[250-2]
## 250
## 17.58407
predict(cubic)[250-2]
## 250
## 17.63041
predict(natty)[250-2]
## 250
## 17.67364
predict(smooth, 250)
## $x
## [1] 250
##
## $y
## [1] 18.55003