R random forest : data (x) has 0 rows -
i using randomforest
function randomforest package find important variable: dataframe called urban , response variable revenue numeric.
urban.random.forest <- randomforest(revenue ~ .,y=urban$revenue, data = urban, ntree=500, keep.forest=false,importance=true,na.action = na.omit)
i following error:
error in randomforest.default(m, y, ...) : data (x) has 0 rows
on source code related x
variable:
n <- nrow(x) p <- ncol(x) if (n == 0) stop("data (x) has 0 rows")
but cannot understand x
.
i solved that. had columns values na or same. dropped them , went ok. columns classes character, numeric , factor.
candidatesnodata.index <- c() (j in (1 : ncol(dataframe))) { if ( is.numeric(dataframe[ ,j]) & length(unique(as.numeric(dataframe[ ,j]))) == 1 ) {candidatesnodata.index <- append(candidatesnodata.index,j)} } dataframe <- dataframe[ , - candidatesnodata.index]
Comments
Post a Comment