Revision a6a4107a08051dfddc3c733102d002fd8617ab9e authored by Lars Kotthoff on 25 October 2014, 00:00:00 UTC, committed by Gabor Csardi on 25 October 2014, 00:00:00 UTC
1 parent c389439
Raw File
selector.random.forest.R
### RANDOM FOREST
# classification and regression
# continous and discrete data
# NA deleted
random.forest.importance <- function(formula, data, importance.type = 1) {
	new_data = get.data.frame.from.formula(formula, data)

	# get rid of NAs
	no_na = rep(TRUE, dim(new_data)[1])
	for(i in 1:dim(new_data)[2]) {
		no_na = no_na & complete.cases(new_data[, i])
	}
	new_data = new_data[no_na, , drop=FALSE]
	
	forest = randomForest(formula, new_data,
		ntree = 1000, keep.forest = FALSE, importance = TRUE)
		
	res = as.data.frame(importance(forest, type = importance.type))
	colnames(res)[1] = "attr_importance"
	return(res)
}
back to top