-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwin_predictor.py
More file actions
35 lines (29 loc) · 1.3 KB
/
Copy pathwin_predictor.py
File metadata and controls
35 lines (29 loc) · 1.3 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
import pandas as pd
import pickle
from game_state import GameState
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPClassifier
from sklearn import preprocessing
from config import Config
#Predicts the round or set win given current state
class WinPredictor:
round_model: MLPClassifier
set_model: MLPClassifier
name_le: preprocessing.LabelEncoder
def __init__(self):
print(Config.get('round_model_path'))
with open(Config.get('round_model_path'), "rb") as f:
self.round_model = pickle.load(f)
with open(Config.get('set_model_path'), "rb") as f:
self.set_model = pickle.load(f)
def predict_win_round(self, current_state: GameState):
df= pd.DataFrame([current_state.flatten()])
round_feature_cols = Config.get('pred_round_features')
current_x = df.loc[:, round_feature_cols]
return self.round_model.predict_proba(current_x)
def predict_win_set(self, current_round_pred: float, current_state: GameState):
df= pd.DataFrame([current_state.flatten()])
set_feature_cols = Config.get('pred_set_features')
current_x = df.loc[:, set_feature_cols]
current_x['current_round_pred'] = current_round_pred
return self.set_model.predict_proba(current_x)