swh:1:snp:0f920b1e114986636ba2e45b5c1a83473fb6cf12
Raw File
Tip revision: 12acd76ec1d613505e4bb20b3012e8d8507a310a authored by Lars Kotthoff on 16 May 2018, 20:38:09 UTC
version 0.31
Tip revision: 12acd76
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