-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExpertAnalysis.py
More file actions
112 lines (81 loc) · 2.59 KB
/
Copy pathExpertAnalysis.py
File metadata and controls
112 lines (81 loc) · 2.59 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
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
101
102
103
104
105
106
107
108
109
110
111
112
#%%
import csv
import os
import pandas as pd
import numpy as np
import sklearn as sk
from sklearn import model_selection
from sklearn import preprocessing
from sklearn import ensemble
from sklearn import naive_bayes
#%%
df = pd.read_csv("all_game_data.csv")
df.head()
print(df.columns)
print(df["lobby_mode"].value_counts())
print(df["lobby_type"].value_counts())
#%%
print("Mean Kills:", df["kills"].mean())
print("Mean Deaths: ", df["deaths"].mean())
print("Mean Turfed Ink:", df["turfed_ink"].mean())
print("Top 5 Weapons: " ,df["weapon_name"].value_counts()[:5])
#%%
gm_group = df["game_mode"].unique()
for game_mode in gm_group:
#print(game_mode)
print("Top 5 Weapons in",game_mode, df[df["game_mode"] == game_mode]["weapon_name"].value_counts()[:5])
print("Map Mode Combos", df[df["game_mode"] == game_mode]["game_map"].value_counts())
#%%
map_group = df["game_map"].unique()
for map_name in map_group:
print("Top 5 Weapons in",map_name, df[df["game_map"] == map_name]["weapon_name"].value_counts()[:5])
#%%
print(df["game_mode"].value_counts())
print(df["game_map"].value_counts())
#%%
# Start with ensemble learning.
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import train_test_split
data = df[:]
Y = list(df["result"])
del df['result']
del df['game_id']
X = df[:]
enc = preprocessing.OrdinalEncoder()
min_max_scaler = preprocessing.MinMaxScaler()
X = enc.fit_transform(X)
X = min_max_scaler.fit_transform(X)
print(X)
for i in range(len(Y)):
if Y[i] == "win":
Y[i] = 1
else:
Y[i] = 0
print(Y)
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.33)
#%%
from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier(max_depth=3)
clf.fit(X_train,y_train)
scores = model_selection.cross_val_score(clf, X_test, y_test, cv=10)
print(scores)
#%%
#Testing Gausian Naiive bayes
gnb = naive_bayes.GaussianNB()
gnb.fit(X_train, y_train)
scores = model_selection.cross_val_score(gnb, X_test, y_test, cv=10)
print(scores)
#%%
d_tree = DecisionTreeClassifier(max_depth=3)
aba = ensemble.AdaBoostClassifier(base_estimator=d_tree, n_estimators=50)
params ={
"base_estimator__criterion": ["gini", "entropy"],
"base_estimator__splitter": ["best", "random"]
}
cv_n = model_selection.KFold(n_splits=20, shuffle=True)
cv_search = model_selection.GridSearchCV(aba, param_grid=params, scoring="average_precision", cv=cv_n, refit=True, n_jobs=2)
cv_search.fit(X_train, y_train)
print(cv_search.score(X_test,y_test))
from joblib import dump, load
dump(cv_search.best_estimator_, 'best_classifier.joblib')
#%%