3
$\begingroup$

I am trying to use featurePlot of caret in R.

This is the code I am using:

trellis.par.set(theme = col.whitebg(), warn = FALSE) 
caret::featurePlot(x = df[, 3:6], 
            y = df$ud, 
            plot = "scatter")

where all the columns of df[, 3:6]are of numeric type, while df$ud is a binary factor.

I also have installed the library ellipse as suggested elsewhere.

However, I keep getting NULL.

Any idea why?

$\endgroup$
1
  • $\begingroup$ Take a look at help(featurePlot) in caret for the expected class of the argument, x, which is a matrix $\endgroup$ Commented Nov 7, 2019 at 5:48

3 Answers 3

4
$\begingroup$

I had this problem due to my y variable not being a factor which is required. call:

typeof(df$ud)

make sure it is not interpreting the binary as character or numeric but indeed ad a factor.

$\endgroup$
1
$\begingroup$

I had the same issue and I fixed it by converting the Y variable to a factor. Add as.factor() to your Y variable. So your code should look like:

trellis.par.set(theme = col.whitebg(), warn = FALSE) 
caret::featurePlot(x = df[, 3:6], 
            y = as.factor(df$ud), 
            plot = "scatter")
$\endgroup$
1
$\begingroup$

I have the same problem with my dataset. The issue was with my character column. For using featurePlot you have to pass only numeric and factor as you independent variables and dependent variable. You can use str() function to check your dataframe and then use as.factor() in order to change character to factor.

For example: the Purchase variable in my dataframe was in character type so I use below code to change it into factor type.

traindata$Purchase <- as.factor(traindata$Purchase) 

after that featurePlot worked fine.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.