[R] contrasts can be applied only to factors with 2 or more levels

Patrick (Malone Quantitative) m@|one @end|ng |rom m@|onequ@nt|t@t|ve@com
Fri Dec 20 21:08:15 CET 2019


Seems self-explanatory. It sounds like one of your predictors has no
variability.

On Fri, Dec 20, 2019 at 3:01 PM javed khan <javedbtk111 using gmail.com> wrote:
>
> I am using the folowing code and it give me the error message like
>
> " contrasts can be applied only to factors with 2 or more levels".
>
> What could be the problem
>
> d=read.csv("Result.csv")
> index <- createDataPartition(log10(d$Results), p = .70,list = FALSE)
> tr <- d[index, ]
> ts <- d[-index, ]
> index_2 <- createFolds(log10(tr$Results), returnTrain = TRUE, list = TRUE)
> ctrl <- trainControl(method = "cv", index = index_2)
>
> set.seed(30218)
>
> grid_search <- train(log10(Results) ~ ., data = tr,
>                      method = "svmRadial",
>
>                      tuneLength = 8,
>                      metric = "MAE",
>                      preProc = c("center", "scale", "zv"),
>                      trControl = ctrl)
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.



More information about the R-help mailing list