Showing
3 changed files
with
52 additions
and
0 deletions
2018-capstone/2018-capstone/c5_model.rds
0 → 100644
No preview for this file type
2018-capstone/c5_model.rds
0 → 100644
No preview for this file type
2018-capstone/model.r
0 → 100644
1 | +df<-read.csv('result_4.csv') | ||
2 | +tail(df,10) | ||
3 | +set.seed(2) | ||
4 | +id<-sample(2,nrow(df),prob = c(0.8,0.2), replace = TRUE) | ||
5 | +train<-df[id==1,] | ||
6 | +test<-df[id==2,] | ||
7 | +tail(test,2) | ||
8 | + | ||
9 | +library(C50) | ||
10 | +model <- readRDS("./c5_model.rds") | ||
11 | + | ||
12 | +prob <- predict(model, newdata = test[1:1, 1:126], type = "prob") | ||
13 | +max1 <- 0 | ||
14 | +max2 <- 0 | ||
15 | +max3 <- 0 | ||
16 | +idx1 <- -1 | ||
17 | +idx2 <- -1 | ||
18 | +idx3 <- -1 | ||
19 | + | ||
20 | +for(i in 1:17){ | ||
21 | + if(max1 < prob[1:1,i:i]){ | ||
22 | + max3 <- max2 | ||
23 | + max2 <- max1 | ||
24 | + max1 <- prob[1:1,i:i] | ||
25 | + idx3 <- idx2 | ||
26 | + idx2 <- idx1 | ||
27 | + idx1 <- i | ||
28 | + } | ||
29 | + else{ | ||
30 | + if(max2 <prob[1:1,i:i]){ | ||
31 | + max3 <- max2 | ||
32 | + max2 <- prob[1:1,i:i] | ||
33 | + idx3 <- idx2 | ||
34 | + idx2 <- i | ||
35 | + } | ||
36 | + else{ | ||
37 | + if(max3 <prob[1:1,i:i]){ | ||
38 | + max3 <-prob[1:1,i:i] | ||
39 | + idx3 <-i | ||
40 | + } | ||
41 | + } | ||
42 | + } | ||
43 | +} | ||
44 | + | ||
45 | +library(ggplot2) | ||
46 | +v <-c("51","54,51","56","56,51","56,54,51","59","59,51","59,56,51","59,56,54,51", | ||
47 | + "61,51","61,54,51","61,56,51","61,56,54,51","61,59,51","61,59,54,51", | ||
48 | + "61,59,56,51","61,59,56,54,51") | ||
49 | +plot <- list(data.frame(idx=toString(v[idx1]),probability=max1),data.frame(idx=toString(v[idx2]),probability=max2),data.frame(idx=toString(v[idx3]),probability=max3)) | ||
50 | +newplot <- do.call(rbind,plot) | ||
51 | +p <- ggplot(newplot,aes(idx,probability))+geom_bar(stat="identity",fill = "blue") | ||
52 | +ggsave(file="~/bar_plot.png",plot=p,dpi=300) |
-
Please register or login to post a comment