[R] $ opetator is invalid for atomic vectors

javed khan j@vedbtk111 @end|ng |rom gm@||@com
Tue Feb 25 00:10:59 CET 2020


I want to compare the same algorithm (mentioned below) on two different
type of datasets. But when I
rvalues=resamples(list(mod, mod2)) , it gives me error:
Object mod2 not found   (note: code works fine with mod but with mod2, it
gives error)

It is strange because the code is exactly same, but one I named mod and
another mod2

The code is here:

obj <- function(param, maximize = FALSE) {
  print(param)
  mod <- train(Result ~ ., data = tr,
               method = "gbm",
               metric = "MAE",
               trControl = ctrl
                                   tuneGrid = data.frame(n.trees =
(param[1]), interaction.depth = (param[2]),
                                shrinkage=(param[3]),
n.minobsinnode=(param[4])))

                if(maximize)
    -getTrainPerf(mod)[, "TrainMAE"] else
      getTrainPerf(mod)[, "TrainMAE"]
}
library(GA)
set.seed(45642)
ga_res <- ga(type = "real-valued",
             fitness = svm_obj,
             min = c(0.5,0), max = c(1,1),

             maxiter = ceiling(num_mods),
             maximize = TRUE)
ga_res using solution


Then I changed the dataset i.e data2 (in the same file) but algorithm is
same, except the mod in train () becomes mod2, in order to draw later the
plot as

rvalues=resamples(list(mod, mod2))    /// mod for one dataset and mod2 for
another dataset
bwplot(rvalues, metric="MAE")

On Mon, Feb 24, 2020 at 7:04 PM Rui Barradas <ruipbarradas using sapo.pt> wrote:

> Hello,
>
> Please cc the list.
> Yes, I believe so, it's hard to say, the code is not reproducible.
> But that's what the docs say. Why not try it?
>
> Hope this helps,
>
> Rui Barradas
>
> Às 16:00 de 24/02/20, javed khan escreveu:
> >
> > Thanks for your feedback Rui.. It means I have to specify the "mod" in
> > the resamples (based on the code below) instead of ga_res?  mod here is
> > the train function of caret?
> >
> > resamples(list( First_data= mod, Second_data=mod2)
> >
> > My sample code is here
> >
> > obj <- function(param, maximize = FALSE) {
> >    print(param)
> >    mod <- train(Result ~ ., data = tr,
> >                 method = "gbm",
> >                 metric = "MAE",
> >                 trControl = ctrl
> >                                     tuneGrid = data.frame(n.trees =
> > (param[1]), interaction.depth = (param[2]),
> >                                  shrinkage=(param[3]),
> > n.minobsinnode=(param[4])))
> >
> >                  if(maximize)
> >      -getTrainPerf(mod)[, "TrainMAE"] else
> >        getTrainPerf(mod)[, "TrainMAE"]
> > }
> >
> > Then GA function
> >
> > library(GA)
> > set.seed(45642)
> > ga_res <- ga(type = "real-valued",
> >               fitness = svm_obj,
> >               min = c(0.5,0), max = c(1,1),
> >
> >               maxiter = ceiling(num_mods),
> >               maximize = TRUE)
> > ga_res using solution
> >
> > On Mon, Feb 24, 2020 at 2:03 PM Rui Barradas <ruipbarradas using sapo.pt
> > <mailto:ruipbarradas using sapo.pt>> wrote:
> >
> >     Hello,
> >
> >     If you are using function resamples from package caret, just read its
> >     help page. From ?resamples, section Arguments:
> >
> >     Arguments
> >
> >     x
> >     a list of two or more objects of class train, sbf or rfe with a
> common
> >     set of resampling indices in the control object. For sort.resamples,
> it
> >     is an object generated by resamples.
> >
> >
> >     Your x argument is not an object of one of those classes. You are
> >     passing the function a list of 2 numeric values, not an object
> >     resembling the examples in that help page.
> >
> >
> >     Hope this helps,
> >
> >     Rui Barradas
> >
> >
> >     Às 11:35 de 24/02/20, javed khan escreveu:
> >      > Hello
> >      >
> >      > I am using genetic algorithm for some optimization problem. I
> >     executed it
> >      > with 2 types of data and get results like
> >      >
> >      > GA=40
> >      > GA2=60
> >      >
> >      > When I combine it with resamples
> >      >
> >      > Value=resamples (list (GA, GA2))
> >      >
> >      > It gives me the error
> >      >
> >      > $ operator is invalid for atomic vectors.
> >      >
> >      > What should be the issue here?
> >      >
> >      > Thanks
> >      >
> >      >       [[alternative HTML version deleted]]
> >      >
> >      > ______________________________________________
> >      > R-help using r-project.org <mailto:R-help using r-project.org> mailing list
> >     -- To UNSUBSCRIBE and more, see
> >      > https://stat.ethz.ch/mailman/listinfo/r-help
> >      > PLEASE do read the posting guide
> >     http://www.R-project.org/posting-guide.html
> >      > and provide commented, minimal, self-contained, reproducible code.
> >      >
> >
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list