The Caret Package
来源:互联网 发布:淘宝当季新品怎么设置 编辑:程序博客网 时间:2024/05/16 04:07
今天再用逻辑斯特回归做模式识别作业,忽然发现了神经网络包 ,遂看了一下 持续更新
#载入DMwR包library(DMwR) #载入nnet(神经网络)包library(nnet) #利用read.table读取数据original.data = read.table("E:/MyDownloads/dataset/dataset/test.data",header = FALSE,sep = " ")#给第11列命名为“label"colnames(original.data)[11] ="label"#for(i in 1:nrow(original.data)){# if(original.data[i,"label"] == 1)# original.data[i,"label"] = "a"# if(original.data[i,"label"] == -1)# original.data[i,"label"] = "b"#}#调用神经网络函数 nn <- nnet(label~.,original.data, size = 10, decay = 0.01, maxit = 1000, linout = T, trace = F) norm.preds <- predict(nn, original.data) norm.preds[which(norm.preds>0)] = 1norm.preds[which(norm.preds<0)] = -1a =table(norm.preds,original.data$label) head(a)#linout 默认是逻辑输出, T为线性输出#maixt 最大迭代次数#size 隐层数量
caret包是一个功能很强大的包, 有通用接口函数train(), 用来调用各种训练方法 我们以’nnet ‘网络为例
library(caret)#载入DMwR包library(DMwR) #载入nnet(神经网络)包library(nnet) traindata 可以自己使用iris数据#get index for seperate data.#split dataset automatically.trainIndex <- createDataPartition(traindata$a, p = .8, list = FALSE, times = 1)head(trainIndex)#as far as I thought data should not have factor variables#tune parameters my.grid <- expand.grid(.decay = c(0,0.5, 0.1), .size = c(4, 5, 6, 7))#nnetfit <- train(y~x, train.dat, method = 'nnet', linout = TRUE, trace = FALSE, tuneGrid = my.grid)#when predict, newdata feature label should be the same as data, except for label.(重要,不然会出错)pred_y <- predict(fit$finalModel, newdata = data.frame(x = test.dat$x))
caret 包功能强大各种数据处理, cross validation, sampling, data preprocess.
机器学习比赛用R语言的话最好把 caret包学习一下
用的到的话推荐网址caret learning tutor
0 0
- The Caret Package
- 1. 简介(The caret package )
- 2. 可视化(The caret package)
- 3. 预处理(The caret package)
- 4. 数据分割(The caret package)
- 6. 可用模型(The caret package )
- 5. 模型训练和调参(The caret package)
- 8. 随机超参搜索(The caret package)
- 9. 类别不平衡的二次抽样(The caret package)
- R package: Caret
- Where has the caret gone?
- Win32 Series - The Caret (Not the Cursor)
- 光标(Caret)
- 解决:The declared package..does not match the expected package..
- The declared package "" does not match the expected package
- The declared package does not match the expected package
- The declared package "" does not match the expected package "javaControlSql"
- The declared package does not match the expected package
- Sort Colors
- Java ConcurrentModificationException异常原因和解决方法
- assets中放入含中文文件名导致编译错误
- ACM篇:POJ 3630 -- Phone Number
- recyclerview之item点击事件监听
- The Caret Package
- 快速排序
- 【ROS】移动机器人导航仿真(3)——定位(amcl)和路径规划(move_base)
- MySQL Group Replication 介绍
- Git命令详解(下)
- Centos7安装完提示Initial setup of CentOS Linux 7 (core)
- UEditor在项目中的应用
- Maven学习 (二) Eclipse 上安装 Maven3插件
- UVa - 10369 - Arctic Network ( 最小生成树 Kruscal )