Maxim Haytovich Maxim Haytovich - 7 days ago 5
R Question

R boruta package - (list) object cannot be coerced to type 'double'

I am trying to run a boruta feature selection on my data set.

The code is below:

df<-read.csv('F:/DataAnalyticsClub/DACaseComp/DatasetDist/Datasets/BestFile.csv',stringsAsFactors=FALSE )
install.packages("Boruta")
library(Boruta)
df[is.na(df)] <- 0
df[df == ""] <- 0
X<-df[ , -which(names(df) %in% c("PREVSALEDATE","PREVSALEDATE2","ClassLabel", "PARID", "PROPERTYUNIT", "PriceDiff1", "PriceDiff2", "DateDiff1", "DateDiff2", "SALEDATE"))]
Y<-df['ClassLabel']



factorCols <- c("SCHOOLDESC","MUNIDESC","SALEDESC","INSTRTYPDESC","NEIGHDESC","TAXDESC","TAXSUBCODE_DESC","OWNERDESC","USEDESC","LOTAREA","CLEANGREEN","FARMSTEADFLAG","ABATEMENTFLAG","COUNTYEXEMPTBLDG","STYLEDESC","EXTFINISH_DESC","ROOFDESC","BASEMENTDESC","GRADEDESC","CONDITIONDESC","CDUDESC","HEATINGCOOLINGDESC","BSMTGARAGE")
nonFactorCols<-c("PRICE","COUNTYTOTAL","LOCALTOTAL","FAIRMARKETTOTAL","STORIES","YEARBLT","TOTALROOMS","BEDROOMS","FULLBATHS","HALFBATHS","FIREPLACES","FINISHEDLIVINGAREA","PREVSALEPRICE","PREVSALEPRICE2")

X[factorCols] <- lapply(X[factorCols], factor)

set.seed(123)
boruta.train<-Boruta(X,Y)


So you see that I have a data set of different features, some of them are string features, so I convert them to factors. The rest is numeric. I test my assumptions:
enter image description here
And once I run the Boruta I get

Error in data.matrix(data.selected) :
(list) object cannot be coerced to type 'double'


I am not sure why. All of my columns are Factors or varoius numeric types. What can be wrong?

After googling a bit I found that some people recommend to do the as.matrix() conversion, but in such case:

> boruta.train<-Boruta(as.matrix(X),as.matrix(Y))
Error: Variable none not found. Ranger will EXIT now.
Error in ranger::ranger(data = x, dependent.variable.name = "shadow.Boruta.decision", :
User interrupt or internal error.

Answer

Ok, after playing around with that I managed to identify the problem. Boruta requires Y (target) to be of the list type, not dataframe or anything else.

So just creating Y like this:

Y<-df[,'ClassLabel']

Solves the problem.