Skip to content

Commit

Permalink
filter constant features
Browse files Browse the repository at this point in the history
  • Loading branch information
tdhock committed Apr 5, 2017
1 parent b007c24 commit 127dd33
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions R/iregnet.R
Original file line number Diff line number Diff line change
Expand Up @@ -208,15 +208,20 @@ iregnet <- function(x, y,
family <- trans$dist
}

sd.vec <- apply(x, 2, sd)
is.constant <- sd.vec==0
x.filtered <- x[, !is.constant, drop=FALSE]
stopifnot_error("no non-constant features", ncol(x.filtered))

# Get column names
varnames <- colnames(x)
varnames <- colnames(x.filtered)
if (is.null(varnames)) {
varnames <- paste('x', 1: n_vars, sep='')
}

# Append col of 1's for the intercept
if (intercept) {
x <- cbind(rep(1, n_obs), x)
x.train <- cbind(rep(1, n_obs), x.filtered)
varnames = c("(Intercept)", varnames)
}

Expand All @@ -225,10 +230,20 @@ iregnet <- function(x, y,
stopifnot_error("eps_lambda should be between 0 and 1", 0 <= eps_lambda && eps_lambda < 1)

# Call the actual fit method
fit <- fit_cpp(x, y, family, alpha, lambda_path=lambda, num_lambda=num_lambda, intercept=intercept,
out_status=status, scale_init=scale_init, max_iter=maxiter, threshold=threshold,
flag_standardize_x=standardize, estimate_scale=estimate_scale, unreg_sol=unreg_sol,
eps_lambda=eps_lambda, debug=debug);
fit <- fit_cpp(
x.train, y, family, alpha,
lambda_path=lambda,
num_lambda=num_lambda,
intercept=intercept,
out_status=status,
scale_init=scale_init,
max_iter=maxiter,
threshold=threshold,
flag_standardize_x=standardize,
estimate_scale=estimate_scale,
unreg_sol=unreg_sol,
eps_lambda=eps_lambda,
debug=debug);

fit$call <- match.call()
fit$intercept <- intercept
Expand Down

0 comments on commit 127dd33

Please sign in to comment.