-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdota_mcts.Rmd
101 lines (81 loc) · 1.78 KB
/
dota_mcts.Rmd
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
---
title: "dota_mcts"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
setwd('/Users/Isolachine/Downloads')
df <- read.csv('lineups.csv')
hero <- read.csv('hero_data.csv')
```
```{r}
summary(df)
dim(df)[1]
```
```{r}
df.all <- data.frame()
df.sparse <- data.frame()
processed = 0
for (i in 1:dim(df)[1]) {
game.vector <- matrix(data = 0, ncol = 113)
count = 0
for (v in df[i,]) {
if (count == 0) {
game.vector[113] = as.integer(v) - 1
} else if (count <= 5) {
game.vector[v] <- 1
} else {
game.vector[v] <- -1
}
count = count + 1
}
names(game.vector) <- 1:113
df.sparse <- rbind.data.frame(df.sparse, game.vector)
processed = processed + 1
if (processed %% 1000 == 0) {
print(paste('processed:', processed))
df.all <- rbind.data.frame(df.all, df.sparse)
df.sparse <- data.frame()
}
}
```
```{r}
df.sparse[,113]
```
```{r}
write.csv(df.all, file = 'sparse.csv')
```
```{r}
cutoff <- 30000
trainset <- df.all[1:cutoff, ]
testset <- df.all[(cutoff + 1):dim(df.all)[1], ]
```
```{r}
n <- names(df.all)
formula <- as.formula(paste("V113 ~", paste(n[!n %in% "V113"], collapse = " + ")))
library(neuralnet)
```
```{r}
nn <- neuralnet(formula = formula, data = trainset, hidden=0, linear.output=FALSE, threshold=0.01)
nn$result.matrix
plot(nn)
```
```{r}
#Test the resulting output
temp_test <- subset(testset, select = n[!n %in% "V113"])
head(temp_test)
nn.results <- compute(nn, temp_test)
results <- data.frame(actual = testset$V113, prediction = nn.results$net.result)
results
```
```{r}
roundedresults<-sapply(results,round,digits=0)
roundedresultsdf=data.frame(roundedresults)
attach(roundedresultsdf)
cf <- table(actual,prediction)
cf
acc <- (cf[1,1] + cf[2,2]) / sum(cf)
acc
```