Skip to content

Refactor variance thresholding #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 23, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions R/variance_thresholding.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @param data tibble. The features to select from
#' @param threshold double. The variance threshold
#'
#' @return vector. The indexes of selected features
#' @return double vector. The indexes of selected features
#' @export
#' @examples
#' data <- data.frame(x1=c(1,2,3,4,5), x2=c(0,0,0,0,0), x3=c(1,1,1,1,1))
Expand All @@ -22,15 +22,14 @@ variance_thresholding <- function(data, threshold = 0) {
}

selected_feature_indexes <- c()
i <- 1
for (name in names(data)) {
for (i in 1:length(names(data))) {
# Get variance of a column
var_i <- stats::var(data[,i])

if (var_i > threshold) {
# Add the column to the selected pile if variance's above the threshold
selected_feature_indexes <- c(selected_feature_indexes, i)
}

i <- i + 1
}

selected_feature_indexes
Expand Down