#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]