Caret

#practice to use the caret packages
#1.variance near to 0 return:a vector of integers corresponding to the column
#positions of the problematic predictors.

Zero <- nearZeroVar(mdrrDescr)
mdrrDescr <- mdrrDescr[,-Zero]

#2.find variables having strong relations with findcorrelation function
#另一类需要删除的是与其它自变量有很强相关性的变量,对应的命令是findcorrelation。自变量中还有可能存在多重共线性问题,
#可以用findLinearCombos命令将它们找出来。

corr <- cor(mdrrDescr)
highcorr <- findCorrelation(corr)
mdrrDescr <- mdrrDescr[,-highcorr]
move <- findLinearCombos(mdrrDescr)

#this function will return a list and use the result remove to remove the useless colum
返回0说明没有共线性了
Pre-processing transformation (centering, scaling etc.) can be estimated from the training data and
applied to any data set with the same variables.
我可以从mdrr里学习一些填补缺失值的规则。然后用到新的数据集上

process <- preProcess(mdrrDescr)
mdrr <- predict(process,mdrrDescr)

最后是用createDataPartition将数据进行划分,分成75%的训练样本和25%检验样本,
类似的命令还包括了createResample用来进行简单的自助法抽样,
还有createFolds来生成多重交叉检验样本。

inTrain = createDataPartition(mdrrClass, p = 3/4, list = FALSE)#devide the data with class
trainx = mdrr[inTrain,]
testx = mdrr[-inTrain,]
trainy = mdrrClass[inTrain]
testy = mdrrClass[-inTrain]
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值