forked from jsihota/GTMachineLearning_Assignment_1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trying.R
51 lines (40 loc) · 1.02 KB
/
Trying.R
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
setwd("~/git/GTMachineLearning_Assignment_1/poker")
#setwd("~/class/GTMachineLearning_Assignment_1/poker")
train <- read.csv("train.csv")
head(train)
#labels = as.factor(train$hand)
#train = train[,1:10]
#head(train)
library(rpart)
CART.fit <- rpart(hand ~., data=train,
control=rpart.control(minsplit=2, minbucket=1, cp=0.001))
summary(CART.fit)
#plot(CART.fit)
library(rattle)
library(rpart.plot)
library(RColorBrewer)
#fancyRpartPlot(CART.fit)
#plotcp(CART.fit)
ptree <- prune(CART.fit,cp=CART.fit$cptable[which.min(CART.fit$cptable[,"xerror"]),"CP"])
#plotcp(ptree)
#fancyRpartPlot(ptree)
test <- read.csv("test.csv")
head(test)
#Get rid of ID column
test = test[,2:11]
head(test)
prediction <- predict(ptree, newdata=test)
summary(prediction)
head(prediction)
#pre <- formatC(prediction, format="f", digits=0)
#sss <- factor(pre)
head(sss)
head(pre)
library(caret)
sub <- read.csv("sampleSubmission.csv")
sub = sub[,2:2]
head(sub)
#aaa <- factor(sub)
summary(sss)
confusionMatrix(sss,aaa)
table(prediction)