DataGuy
DataGuy

Reputation: 1725

Plotting varImp in R

Im using the varImp function of the caret package and Im trying to plot the resulting dataframe that it creates. Here is the code:

RocImp2 <- varImp(svmFit, scale = FALSE)

and Im using a simple plot to plot the chart:

plot(RocImp2)

The results are supposed to look like this:

enter image description here

whereas mine looks like this:

enter image description here

Here is a copy of the dataframe:

enter image description here

disregard the names in the plot as they are from another example.

Upvotes: 2

Views: 9900

Answers (4)

Paulo Rogerio Lima
Paulo Rogerio Lima

Reputation: 1

The most simple way to plot: plot(varImp(RocImp2))

Upvotes: 0

younes lahouir
younes lahouir

Reputation: 31

here is a solution to plot the varImp in the case of a binary classification model.

model = glm(Survived~.,family="binomial", data=Titanic)

V = caret::varImp(model)

ggplot2::ggplot(V, aes(x=reorder(rownames(V),Overall), y=Overall)) +
geom_point( color="blue", size=4, alpha=0.6)+
geom_segment( aes(x=rownames(V), xend=rownames(V), y=0, yend=Overall), 
color='skyblue') +
xlab('Variable')+
ylab('Overall Importance')+
theme_light() +
coord_flip() 

Upvotes: 3

Lucas
Lucas

Reputation: 111

My issue was fixed by adding the following.

ggplot2::ggplot(varImp())

Upvotes: 5

Milad Botros
Milad Botros

Reputation: 1

I found a workaround this problem. You could try:

write.csv(RocImp2, file = 'RocImp2.csv')

VIMP <- read.csv('RocImp2.csv')

plot(VIMP)

Upvotes: -1

Related Questions