请教各位大神,新手学R,写了下面做回归阶次比较的代码,系统老提示ggplot函数不存在,不知道是代码错了,还是什么问题,ggplot2也下载了啊。
library(MASS)
attach(Boston)
dis=seq(0,1,by=0.01)
nox=sin(2*pi*dis)+rnorm(length(dis),0,0.1)
data1=data.frame(dis,nox)
set.seed(1)
index=nrow(data1)
index1=sample(index,round(0.5*index))
trainingdata=data1[index1,]
testingdata=data1[-index1,]
Performance=data.frame()
for(d in 1:15)
{
polyfit=lm(nox~poly(dis,degree = d),data=trainingdata)
Performance=rbind(Performance,data.frame(Degree=d,
Data='Train',
rmse=RMSE(trainingdata$nox,predict(polyfit))))
Performance=rbind(Performance,data.frame(Degree=d,
Data='Test',
rmse=RMSE(testingdata$nox,predict(polyfit,newdata = testingdata))))
}
ggplot(Performance,aes(Degree,rmse,linetype=Data))+geom_point()+geom_line()


雷达卡





京公网安备 11010802022788号







