Created
December 23, 2013 08:17
-
-
Save multidis/8093372 to your computer and use it in GitHub Desktop.
Revisions
-
multidis revised this gist
Dec 27, 2013 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,4 +10,11 @@ ytst <- yclass[-in.train]; summary(factor(ytst)) Xtra <- scale(X[in.train,]) Xtest <- scale(X[-in.train,], center = attr(Xtra,"scaled:center"), scale = attr(Xtra,"scaled:scale")) ## stratified folds for cross-validation: say Y is a factor table(Y) foldInds <- createFolds(Y, k=10, list=TRUE, returnTrain=FALSE) lapply(foldInds, function(ii) table(Y[ii])) ## verify stratification ## set returnTrain=TRUE if supplyinf these indiced to train-function, ## see https://stat.ethz.ch/pipermail/r-help/2011-May/277722.html -
multidis created this gist
Dec 23, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ library(caret) ## select training indices preserving class distribution in.train <- createDataPartition(yclass, p=0.8, list=FALSE) summary(factor(yclass)) ytra <- yclass[in.train]; summary(factor(ytra)) ytst <- yclass[-in.train]; summary(factor(ytst)) ## standardize features: training parameters of scaling for test-part Xtra <- scale(X[in.train,]) Xtest <- scale(X[-in.train,], center = attr(Xtra,"scaled:center"), scale = attr(Xtra,"scaled:scale"))