Skip to content

Instantly share code, notes, and snippets.

@bdewilde
Created October 27, 2012 16:31
Show Gist options
  • Save bdewilde/3965255 to your computer and use it in GitHub Desktop.
Save bdewilde/3965255 to your computer and use it in GitHub Desktop.
how to remove features with near zero variance, not useful for discriminating classes
# helpful functions for classification/regression training
# http://cran.r-project.org/web/packages/caret/index.html
library(caret)
# get indices of data.frame columns (pixels) with low variance
badCols <- nearZeroVar(train)
print(paste("Fraction of nearZeroVar columns:", round(length(badCols)/length(train),4)))
# remove those "bad" columns from the training and cross-validation sets
train <- train[, -badCols]
cv <- cv[, -badCols]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment