0
votes
library(tidyverse)
library(ggplot2)
library(caret)
varImp(fullFit, scale = FALSE)
plot(varImp(fullFit, scale = FALSE))

> varImp(fullFit, scale = FALSE)
                 Overall
bedrooms       2.9003032
bathrooms      1.9974678
sqft_living   13.5250547
sqft_lot       0.7873693
floors         2.2513678
waterfront    11.2258728
sqft_above     3.4476093
sqft_living15  6.4453136
sqft_lot15     1.9466399

When I try to plot the VarImp it does not plot the variables (bedrooms, bathrooms, etc.) What is the correct way to create a visualization that plots Variable Importance from the caret package?

plot(varImp(fullFit, scale = FALSE))

enter image description here

1
Try print(varImp(fullFit, scale = FALSE)) - Shirin Yavari
Didn't work. :/ - Michael
can you share the dataset you're working with please. When asking for help, you should include a simple reproducible example with sample input and desired output that can be used to test and verify possible solutions. - Shirin Yavari
oh I know you're using the finalModel as your fullFit! you shouldn't! you should use the entire nnet_model not nnet_model$finalModel - Shirin Yavari

1 Answers

0
votes
set.seed(23)
library(caret)
library(mlbench)
data(Sonar)
traincontrol <- trainControl(method = "cv", number = 5, returnResamp = "all",   savePredictions='all', classProbs = TRUE, summaryFunction = twoClassSummary)

nnet_model <- train(Class ~.,
                 data = Sonar,
                 method = "nnet", 
                 trControl = traincontrol,
                 metric = "ROC", 
                 trace = FALSE)

plot(varImp(nnet_model$finalModel, scale = FALSE))#wrong image
plot(varImp(nnet_model, scale = FALSE))#correct image