小编JC.*_*Sun的帖子

为什么R中的h2o.randomForest比randomForest包做出更好的预测

setwd("D:/Santander")

## import train dataset
train<-read.csv("train.csv",header=T)


dim(train)

summary(train)

str(train)

prop.table(table(train2$TARGET))

stats<-function(x){
  length<-length(x)
  nmiss<-sum(is.na(x))
  y<-x[!is.na(x)]
  freq<-as.data.frame(table(y))
  max_freq<-max(freq[,2])/length
  min<-min(y)
  median<-median(y)
  max<-max(y)
  mean<-mean(y)
  freq<-length(unique(y))
  return(c(nmiss=nmiss,min=min,median=median,mean=mean,max=max,freq=freq,max_freq=max_freq))
}


var_stats<-sapply(train,stats)

var_stats_1<-t(var_stats)

###???????????0.9999???????1/10000??????

exclude_var<-rownames(var_stats_1)[var_stats_1[,7]>0.9999]

train2<-train[,! colnames(train) %in% c(exclude_var,"ID")]




rm(list=setdiff(ls(),"train2"))

train2<-train2[1:10000,]

write.csv(train2,"example data.csv",row.names = F)

##??????????????
set.seed(1)
ind<-sample(c(1,2),size=nrow(train2),replace=T,prob=c(0.8,0.2))

train2$TARGET<-factor(train2$TARGET)
train_set<-train2[ind==1,]
test_set<-train2[ind==2,]

rm(train2)
##1\?R randomForest?????? 100??
library(randomForest)

memory.limit(4000)

random<-randomForest(TARGET~.,data=train_set,ntree=50)

print(random)

random.importance<-importance(random)

p_train<-predict(random,train_set,type="prob")

pred.auc<-prediction(p_train[,2],train_set$TARGET)

performance(pred.auc,"auc")

##train_set auc=0.8177


## predict test_set
p_test<-predict(random,newdata = test_set,type="prob")

pred.auc<-prediction(p_test[,2],test_set$TARGET)
performance(pred.auc,"auc")

##test_set auc=0.60


#________________________________________________#

##_________h2o.randomForest_______________

library(h2o)
h2o.init()

train.h2o<-as.h2o(train_set)
test.h2o<-as.h2o(test_set)

random.h2o<-h2o.randomForest(,"TARGET",training_frame = train.h2o,ntrees=50)


importance.h2o<-h2o.varimp(random.h2o)

p_train.h2o<-as.data.frame(h2o.predict(random.h2o,train.h2o))

pred.auc<-prediction(p_train.h2o$p1,train_set$TARGET)

performance(pred.auc,"auc") …
Run Code Online (Sandbox Code Playgroud)

r random-forest h2o

3
推荐指数
1
解决办法
1398
查看次数

标签 统计

h2o ×1

r ×1

random-forest ×1