-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
73 lines (55 loc) · 2.16 KB
/
main.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
import pandas as pd
from sklearn.compose import ColumnTransformer
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn import svm
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import OrdinalEncoder
from sklearn.preprocessing import OneHotEncoder
from sklearn.impute import SimpleImputer
from sklearn.pipeline import Pipeline
from sklearn.metrics import classification_report
data = pd.read_csv("csgo.csv")
print(data.info())
data2 = data.drop(["date", "day", "month", "year", "wait_time_s"], axis=1)
corr = data.corr(numeric_only=True)
print(corr)
target = "result"
x = data2.drop(target, axis=1)
y = data2[target]
print(y.unique())
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=42)
ordinal_result = ["Lost", "Tie", "Win"]
ordinal_transformer = Pipeline(steps=[
("imputer", SimpleImputer(strategy="constant", fill_value="Tie")),
("encoder", OrdinalEncoder(categories=[ordinal_result])),
])
ordinal_feature = ["result"]
#
# result_test = ordinal_transformer.fit_transform(y_train)
numeric_features = ["match_time_s", "team_a_rounds", "team_b_rounds", "ping", "kills", "assists", "deaths", "mvps", "hs_percent", "points"]
numeric_transformer = Pipeline(steps=[
("imputer", SimpleImputer(strategy="median")),
("scaler", StandardScaler())]
)
nominal_transformer = Pipeline(steps=[
("imputer", SimpleImputer(strategy="constant", fill_value="unknown")),
("encoder", OneHotEncoder(sparse=False)),
])
nominal_feature = ["map"]
preprocessor = ColumnTransformer(
transformers=[
("num", numeric_transformer, numeric_features),
# ("ordinal", ordinal_transformer, ordinal_feature),
("nominal", nominal_transformer, nominal_feature),
]
)
clf = Pipeline(
steps=[("preprocessor", preprocessor), ("clf", RandomForestClassifier(max_depth=2, random_state=0))]
)
clf.fit(x_train, y_train)
y_predict = clf.predict(x_test)
for i, j in zip(y_test, y_predict):
print("Actual {}. Predict {}".format(i, j))
print(classification_report(y_test, y_predict))