-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom over sampling
More file actions
53 lines (39 loc) · 1.8 KB
/
Copy pathRandom over sampling
File metadata and controls
53 lines (39 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
install.packages('ROSE')
library(ROSE)
data(hacide)
str(hacide.train)
table(hacide.train$cls)
prop.table(table(hacide.train$cls))
library(rpart)
tree<-rpart(cls~.,data = hacide.train)
predict.tree<-predict(tree,newdata = hacide.test)
accuracy.meas(hacide.test$cls,predict.tree[,2])
roc.curve(hacide.test$cls,predict.tree[,2],plotit = FALSE)
data.balance_over<- ovun.sample(cls~.,data = hacide.train,method = 'over',N=1960)$data
table(data.balance_over$cls)
data.balance_under<-ovun.sample(cls~.,data = hacide.train,method = 'under',N=40)$data
table(data.balance_under$cls)
data.balance_both<-ovun.sample(cls~.,data = hacide.train,method = 'both',p=0.5)$data
table(data.balance_both$cls)
data.rose<-ROSE(cls~.,data = hacide.train,seed = 1)$data
table(data.rose$cls)
tree.rose<-rpart(cls~.,data = data.rose)
predict.rose<-predict(tree.rose,newdata = hacide.test)
accuracy.meas(hacide.test$cls,predict.rose[,2])
roc.curve(hacide.test$cls,predict.rose[,2])
tree.over<-rpart(cls~.,data = data.balance_over)
predict.over<-predict(tree.over,newdata = hacide.test)
accuracy.meas(hacide.test$cls,predict.over[,2])
roc.curve(hacide.test$cls,predict.over[,2])
tree.under<-rpart(cls~.,data = data.balance_under)
predict.under<-predict(tree.under,newdata = hacide.test)
accuracy.meas(hacide.test$cls,predict.under[,2])
roc.curve(hacide.test$cls,predict.under[,2])
tree.both<-rpart(cls~.,data = data.balance_both)
predict.both<-predict(tree.both,newdata = hacide.test)
accuracy.meas(hacide.test$cls,predict.both[,2])
roc.curve(hacide.test$cls,predict.both[,2])
rose.holdout<-ROSE.eval(cls~.,data=hacide.train,learner = rpart,method.assess ='holdout',extr.pred = function(obj)obj[,2],seed = 1)
rose.holdout
rose.boot<-ROSE.eval(cls~.,data=hacide.train,learner = rpart,method.assess ='BOOT',extr.pred = function(obj)obj[,2],seed = 1)
rose.boot