Ошибка в alpha.simulation [jj, ii] <- opt.alpha.ROC (temp1, svm.core.data [fold ==: замена имеет нулевую длину) - PullRequest
0 голосов
/ 15 сентября 2018

У меня ошибка при запуске этой функции. Ошибка читает «Ошибка в alpha.simulation [jj, ii] <- opt.alpha.ROC (temp1, svm.core.data [fold ==: замена имеет нулевую длину». </p>

Я начинающий программист и буду очень признателен за любую помощь.

simulation.opt.alpha.svm.linear = function(formula.class = form.inter.par.svm,
                                           simul = 25, k = 5, cost = opt.cost){
  # Simulated / run the for loops for simul time and k number of folds to calculate the median of variation in alpha value from simulations for LR
  # INPUT : Formula class - Formula for the model
  #       : simul - Number of Simulations
  #       : k - Number of folds
  #       : cost - Optimized cost for linear support vector machine
  # Amit Gajurel - August 29,2018

  jj = 1
  alpha.simulation = matrix(NA,simul,k, dimnames = list(NULL,paste(1:k))) # predefining a matrix for storing mean performance

  for (jj in 1:simul) {
    #ii= 1
    #set.seed(10)
    fold = sample(x = 1:k,size = nrow(svm.core.data), replace = TRUE) # selecting random samples
    for (ii in 1:k) {
      # fitting the data first with train set
      svm.fit = svm(formula.class, 
                    data = svm.core.data[fold!=ii,], 
                    kernel = "linear",
                    cost = cost,
                    decision.value = TRUE) # using 4 out of 5 data part to come up with the model parameters as train set
      temp = predict(svm.fit,
                     newdata = svm.core.data[fold==ii,],
                     decision.values = TRUE)


      temp1 = attributes(temp)$decision.values  * (-1) 

      alpha.simulation[jj,ii] = opt.alpha.ROC(temp1,svm.core.data[fold ==ii,]$y)  #calculating the optimum value of alpha using only test set

    }

  }

  median(alpha.simulation,na.rm = TRUE) %>% return()

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...