1 year ago
#371195
Dimitris Karditsas
Error in eval(predvars, data, env) : object 'model_.B' not found in RandomForest function
$ price : int 11200 27000 16000 12750 14500 14900 16000 16250 14250 14250 ...
$ transmission : Factor w/ 3 levels "Automatic","Manual",..: 1 1 1 1 1 1 1 2 2 1 ...
$ mileage : int 67068 14827 62794 26676 39554 35309 38538 10401 42668 36099 ...
$ fuelType : Factor w/ 4 levels "Diesel","Electric",..: 1 4 1 1 1 1 1 4 1 1 ...
$ tax : int 125 145 160 145 160 125 125 145 30 20 ...
$ mpg : num 57.6 42.8 51.4 72.4 50.4 60.1 60.1 52.3 62.8 68.9 ...
$ engineSize : num 2 2 3 1.5 3 2 2 1.5 2 2 ...
$ automaker : Factor w/ 4 levels "BMW","Ford","Mercedes",..: 1 1 1 1 1 1 1 1 1 1 ...
$ age : int 8 4 6 5 8 6 5 4 5 6 ...
$ model_.1.Series : int 0 0 0 1 0 0 0 0 0 0 ...
$ model_.2.Series : int 0 0 0 0 0 0 0 1 0 0 ...
$ model_.3.Series : int 0 0 0 0 0 0 0 0 0 0 ...
$ model_.4.Series : int 0 0 0 0 0 0 0 0 1 0 ...
$ model_.5.Series : int 1 0 1 0 0 1 1 0 0 1 ...
$ model_.6.Series : int 0 1 0 0 0 0 0 0 0 0 ...
$ model_.7.Series : int 0 0 0 0 1 0 0 0 0 0 ...
$ model_.8.Series : int 0 0 0 0 0 0 0 0 0 0 ...
$ model_.A.Class : int 0 0 0 0 0 0 0 0 0 0 ...
$ model_.Auris : int 0 0 0 0 0 0 0 0 0 0 ...
$ model_.Avensis : int 0 0 0 0 0 0 0 0 0 0 ...
$ model_.Aygo : int 0 0 0 0 0 0 0 0 0 0 ...
$ model_.B-MAX : int 0 0 0 0 0 0 0 0 0 0 ...
$ model_.B.Class : int 0 0 0 0 0 0 0 0 0 0 ...
$ model_.C-HR : int 0 0 0 0 0 0 0 0 0 0 ...
$ model_.C-MAX : int 0 0 0 0 0 0 0 0 0 0 ...
$ model_.C.Class : int 0 0 0 0 0 0 0 0 0 0 ...
Hello! I used the dummy function to separate the levels of factors of my original variable named "model". Then I am trying to do random forrest prediction.(i have fixed the spaces for the column names using gsub). Then I am setting the training and the testing.
n_rows <- nrow(my_final_cars)
training_idx <- sample(n_rows, n_rows * 0.7)
training_my_final_cars <- my_final_cars[training_idx,]
test_my_final_cars <- my_final_cars[-training_idx,]
But when I try the following I get an error at the train function
my_final_cars_formula <- reformulate(names(training_my_final_cars[, -1]), response = 'price')
ctrl_parameters <- trainControl(method = 'CV', number = 5)
modelLookup('rpart')
my_final_cars_tree <- train(my_final_cars_formula, data = training_my_final_cars, method = "rpart", trControl = ctrl_parameters)
my_final_cars_tree
Error in eval(predvars, data, env) : object 'model_.B' not found
model_.B I am 100% sure that it doesnt exist in my dataset. Do you know why it happens to tell me that it doesnt find a variable that shouldnt be found from the moment that there isnt something named like this in my dataset? Do you have any suggetions?
r
random-forest
0 Answers
Your Answer