首页 > 学院 > 开发设计 > 正文

deep learning with R

2019-11-06 09:00:47
字体:
来源:转载
供稿:网友
require(RSNNS)library(neuralnet)set.seed(2016)attribute<-as.data.frame(sample(seq(-2,2,length=50),50,replace=F),ncol=1)response<-attribute^2data<-cbind(attribute,response)colnames(data)<-c("attribute","response")head(data,10)
    attribute   response1  -1.2653061 1.600999582  -1.4285714 2.040816333   1.2653061 1.600999584  -1.5102041 2.280716375  -0.2857143 0.081632656  -1.5918367 2.533944197   0.2040816 0.041649318   1.1020408 1.214493969  -2.0000000 4.0000000010 -1.8367347 3.37359434
fit<-neuralnet(response~attribute,data=data,hidden=c(3,3),threshold = 0.01)testdata<-as.matrix(sample(seq(-2,2,length=10),10,replace=F),ncol=1)PRed<-compute(fit,testdata)result<-cbind(testdata,pred$net.result,testdata^2)colnames(result)<-c("Attribute","Prediction","Actual")round(result,4)
      Attribute Prediction Actual [1,]   -1.5556     2.4213 2.4198 [2,]   -0.2222     0.0364 0.0494 [3,]   -1.1111     1.2254 1.2346 [4,]    1.1111     1.2013 1.2346 [5,]    0.6667     0.4395 0.4444 [6,]    1.5556     2.4521 2.4198 [7,]   -0.6667     0.4554 0.4444 [8,]    0.2222     0.0785 0.0494 [9,]    2.0000     3.9317 4.0000[10,]   -2.0000     3.9675 4.0000
require(Metrics)data("Boston",package="MASS")data<-Bostonkeeps<-c("crim","indus","nox","rm","age","dis","tax","ptratio","lstat","medv")data<-data[keeps]apply(data,2,function(x) sum(is.na(x)))
  crim   indus     nox      rm     age     dis     tax ptratio   lstat       0       0       0       0       0       0       0       0       0    medv       0
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表