# Using Random Forest for big data?

I used Random Forest regression for my work, but now I have another problem because I have really big data. I am using a VHR and this is much raster information. My script in R is this:

``````rand.zero <- apply(rand.riq, 1, function(y) sum(length(which(y > 0))))
hist(rand.zero, breaks=50, col="grey", main="",
ylab="Number of OTUs", xlab="Number of Non-Zero Values")
``````

## Remove zero data

``````remove_rare <- function( table , cutoff_pro ) {
row2keep <- c()
cutoff <- ceiling( cutoff_pro * ncol(table) )
for ( i in 1:nrow(table) ) {
row_nonzero <- length( which( table[ i , ]  > 0 ) )
if ( row_nonzero > cutoff ) {
row2keep <- c( row2keep , i)
}
}
return( table [ row2keep , , drop=F ])
}
``````

## Remove non-zeros values

``````rand_table_rare_removed <- remove_rare(table=rand.riq, cutoff_pro=0.5)
dim(rand_table_rare_removed)

rand_table_rare_removed_norm <- sweep(rand_table_rare_removed, 2, colSums(rand_table_rare_removed) , '/')*100
``````

## Scale or data transformation

``````rand_table_scaled <- scale(rand_table_rare_removed_norm, center = TRUE, scale = TRUE)
dim(rand_table_scaled)
x = nearZeroVar(rand_table_rare_removed)
``````

## Regression

``````rand_table_scaled_IS <- data.frame(t(rand_table_scaled))
rand_table_scaled_IS\$riq <- rand.riq[rownames(rand_table_scaled_IS), "riq"]
set.seed(45)
RF_IS_regress <- randomForest( x=rand_table_scaled_IS[,1:(ncol(rand_table_scaled_IS)-1)] , y=rand_table_scaled_IS[ , ncol(rand_table_scaled_IS)] , ntree=500, importance=TRUE, proximities=TRUE )
print(RF_IS_regress)
``````

And finally the program shows me this error:

``````> Error in randomForest.default(x = rand_table_scaled_IS[,
> 1:(ncol(rand_table_scaled_IS) -  :    NA not permitted in predictors
``````

But I removed zero data and don't exist Nas

• did you try passing the na.action=na.omit to the arguments in randomForest() ? – Elio Diaz Sep 21 '17 at 17:00
• Apply na.omit to your data to eliminate NA values. Alternatively, use the randomForest na.action which accomplishes the same thing but within the function thus, leaving the NA's in your original data. Please note two things: zero values are not the same as NA values and it is not desirable to scale data for random forests models as it can obscure high-dimensional interactions. – Jeffrey Evans Sep 21 '17 at 17:26
• I understand Na and zeroValue is no the same, but when I apply na.action and I have the same problem. I apply na.action in original data, and randomForest – Dinosca Sep 21 '17 at 19:42
• @JeffreyEvans your comment would make a nice answer;) – Aaron Jan 30 '18 at 14:52