Closed mstaniak closed 5 years ago
Error in contrasts<-(*tmp*, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels
contrasts<-
*tmp*
set.seed(17) faktor <- sample(c(0, 1), 500, prob = c(0.5, 0.5), replace = T) table(faktor) set.seed(17) numeric <- rnorm(500) set.seed(17) y <- (-1)^(faktor)*4*numeric + 0.5 + rnorm(500) set.seed(17) X <- data.frame(y = y, x1 = as.factor(faktor), x2 = numeric, x3 = runif(500)) library(randomForest) library(dplyr) X_train <- sample_frac(X, 0.8) X_test <- setdiff(X, X_train) rf_m <- randomForest(y ~., data = X_train, ntree = 1000) mean((predict(rf_m, X_test[, -1]) - X_test[, 1])^2) library(DALEX2) dalex_explainer <- DALEX2::explain(rf_m, data = X_train[, -1]) library(localModel) lm_explanation_4 <- individual_surrogate_model(dalex_explainer, X[4, -1], 1000, 17, gaussian_kernel)
Error in
contrasts<-
(*tmp*
, value = contr.funs[1 + isOF[nn]]) : contrasts can be applied only to factors with 2 or more levels