variadic functions - Unused arguments error in R studio -


i error when try run line of code:

nnetpred.model <- nnetpred(x, y, step_size = 0.4,reg = 0.0002, h=50, niteration = 6000) 

the error message is:

error in nnetpred(x, y, step_size = 0.4, reg = 2e-04, h = 50, niteration = 6000) :  unused arguments (step_size = 0.4, reg = 2e-04, h = 50, niteration = 6000) 

my code below:

nnetpred <- function(x, y, para = list()){   w <- para[[1]]   b <- para[[2]]   w2 <- para[[3]]   b2 <- para[[4]]    n <- nrow(x)   hidden_layer <- pmax(0, x%*% w + matrix(rep(b,n), nrow = n, byrow = t))    hidden_layer <- matrix(hidden_layer, nrow = n)   scores <- hidden_layer%*%w2 + matrix(rep(b2,n), nrow = n, byrow = t)    predicted_class <- apply(scores, 1, which.max)    return(predicted_class)   }  nnetpred.model <- nnetpred(x, y, step_size = 0.4,reg = 0.0002, h=50, niteration = 6000) 

it looks trying use variable arguments. in r, means ellipsis (...). how define top of nnetpred use variable arguments:

nnetpred <- function(x, y, ...) {   para <- list(...) 

this work in case, not best way define function, because looks have finite number of parameters. when have unknown number of parameters should use variable argument lists. recommend putting parameters in parameter list. can rename them if want to:

nnetpred <- function(x, y, step_size, reg, h, niteration) {   w <- step_size   b <- reg   w2 <- h   b2 <- niteration 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -