R语言 多项式回归示例

rm(list=ls())
data <- swiss
data[,1:5] <- scale(data[,1:5])

data1 <- data
for (i in 1:3) {
  mdl <- lm(Examination ~ poly(Education, degree=i), data = data)
  data1[,6+i] <- predict(mdl,data)
}

# 作图
library(ggplot2)
ggplot(data1)+
  geom_point(aes(x=Education,y=Examination))+
  geom_line(data=data1, aes(x=Education,y=V7),color="red")+
  geom_line(data=data1, aes(x=Education,y=V8),color="blue")+
  geom_line(data=data1, aes(x=Education,y=V9),color="green")

R语言 多项式回归 polynomial regression

相关文章:

  • 2021-08-23
  • 2021-12-30
  • 2022-01-12
  • 2021-04-18
  • 2021-06-29
  • 2022-12-23
  • 2021-10-03
猜你喜欢
  • 2022-01-07
  • 2021-11-18
  • 2021-04-03
  • 2022-12-23
  • 2021-08-25
  • 2021-08-14
  • 2021-11-03
相关资源
相似解决方案