R boruta包 - (list)对象不能被强制输入'double'

时间:2016-11-26 22:55:30

标签: r machine-learning feature-selection data-science

我正在尝试在我的数据集上运行boruta功能选择。

代码如下:

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)

所以你看到我有一个不同功能的数据集,其中一些是字符串功能,所以我将它们转换为因子。其余的是数字。我测试我的假设: enter image description here 一旦我运行Boruta,我就得到了

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

我不确定为什么。我的所有列都是因子或varoius数字类型。什么可能是错的?

谷歌搜索后我发现有些人建议进行as.matrix()转换,但在这种情况下:

> 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.

1 个答案:

答案 0 :(得分:0)

好的,在玩完之后我设法找出了问题所在。 Boruta要求Y(目标)属于列表类型,而不是数据帧或其他任何内容。

所以只需像这样创建Y:

Y<-df[,'ClassLabel']

解决问题。