-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDota 2 Game Prediction.py
78 lines (63 loc) · 1.7 KB
/
Dota 2 Game Prediction.py
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
from sklearn import tree
# Open the file and read in data from that.
training_data_file = open("trainingdata.txt")
theList = []
for entry in training_data_file:
entry = entry.strip()
theList.append(entry)
training_data_file.close()
# Initialize a dictionary
db = dict()
# Iterate through each line in theList
i = 0
count = 0
# Each champion is assigned a unique id
for item in theList:
if '1' in item:
champions = item.split(',')
champions.pop()
for j in range(5):
if champions[j] not in db:
db[champions[j]] = count
count += 1
else:
champions = item.split(',')
champions.pop()
j = 5
for j in range(5, 10):
if champions[j] not in db:
db[champions[j]] = count
count += 1
dataChampions = []
dataWinners = []
for item in theList:
data = []
champions = item.split(',')
winner = champions.pop()
dataWinners.append(winner)
j = 0
for j in range(len(champions)):
data.append(db[champions[j]])
j += 1
dataChampions.append(data)
# Import the classifier
my_classifier = tree.DecisionTreeClassifier()
# Train the classifier
my_classifier.fit(dataChampions, dataWinners)
# Test the algorithm
inp = int(input())
inputList = []
for k in range(inp):
line = input()
inputList.append(line)
testChampions = []
for item in inputList:
stringChampions = item.split(',')
intChampions = []
for z in range(10):
intChampions.append(db[stringChampions[z]])
testChampions.append(intChampions)
predictions = my_classifier.predict(testChampions)
# Print the results
for prediction in predictions:
print(prediction)