Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,19 +7,32 @@ from catboost import CatBoostRegressor
|
|
7 |
|
8 |
def predict(team, inning, venue, hits, errors, lob, runs, opp_team, opp_runs, opp_hits):
|
9 |
data = [team, opp_team, inning, venue, hits, opp_hits, errors, runs, opp_runs, lob]
|
|
|
|
|
|
|
|
|
|
|
10 |
df = pd.DataFrame([data], columns=["Team_Name", "Opposition_Team", "Inning", "Home/Away", "Hits", "Opp_Hits", "Errors", "Runs", "Opp_Runs", "LOB"])
|
|
|
11 |
|
|
|
|
|
|
|
|
|
12 |
xgb_model = xgb.XGBRegressor()
|
13 |
-
xgb_model.load_model('
|
14 |
|
15 |
-
with open('
|
16 |
-
|
17 |
-
|
18 |
-
df['Team_Name'] = label_encoder.transform(df['Team_Name'])
|
19 |
-
df['Opposition_Team'] = label_encoder.transform(df['Opposition_Team'])
|
20 |
|
|
|
|
|
|
|
21 |
home_away_status = {'Home': 0, 'Away': 1}
|
22 |
df['Home/Away'] = df['Home/Away'].map(home_away_status)
|
|
|
|
|
|
|
23 |
score = xgb_model.predict(df)
|
24 |
if score[0] < 0:
|
25 |
score = np.clip(score[0], a_min=0, a_max=None)
|
@@ -28,19 +41,33 @@ def predict(team, inning, venue, hits, errors, lob, runs, opp_team, opp_runs, op
|
|
28 |
|
29 |
def predict_2(team, inning, venue, hits, errors, lob, runs, opp_team, opp_runs, opp_hits):
|
30 |
data = [team, opp_team, inning, venue, hits, opp_hits, errors, runs, opp_runs, lob]
|
|
|
|
|
|
|
|
|
|
|
31 |
df = pd.DataFrame([data], columns=["Team_Name", "Opposition_Team", "Inning", "Home/Away", "Hits", "Opp_Hits", "Errors", "Runs", "Opp_Runs", "LOB"])
|
|
|
|
|
|
|
32 |
|
33 |
cat_model = CatBoostRegressor()
|
34 |
-
cat_model.load_model('
|
35 |
|
36 |
-
with open('label_encoder_teams_catbr1_exp1.pkl', 'rb') as f:
|
37 |
-
|
38 |
|
39 |
-
df['Team_Name'] = label_encoder.transform(df['Team_Name'])
|
40 |
-
df['Opposition_Team'] = label_encoder.transform(df['Opposition_Team'])
|
41 |
|
42 |
home_away_status = {'Home': 0, 'Away': 1}
|
43 |
df['Home/Away'] = df['Home/Away'].map(home_away_status)
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
score = cat_model.predict(df)
|
45 |
if score[0] < 0:
|
46 |
score = np.clip(score[0], a_min=0, a_max=None)
|
|
|
7 |
|
8 |
def predict(team, inning, venue, hits, errors, lob, runs, opp_team, opp_runs, opp_hits):
|
9 |
data = [team, opp_team, inning, venue, hits, opp_hits, errors, runs, opp_runs, lob]
|
10 |
+
|
11 |
+
df_main = pd.read_csv("Score_prediction_dataset_11th_July.csv")
|
12 |
+
df_main = df_main.drop(columns=['Final_Score', 'Opp_LOB'])
|
13 |
+
df_main = pd.get_dummies(df_main, columns=['Team_Name', 'Opposition_Team'])
|
14 |
+
|
15 |
df = pd.DataFrame([data], columns=["Team_Name", "Opposition_Team", "Inning", "Home/Away", "Hits", "Opp_Hits", "Errors", "Runs", "Opp_Runs", "LOB"])
|
16 |
+
df = pd.get_dummies(df, columns=['Team_Name', 'Opposition_Team'])
|
17 |
|
18 |
+
df = df.reindex(columns=df_main.columns, fill_value=0)
|
19 |
+
|
20 |
+
# print(df.columns)
|
21 |
+
# print(len(df.columns))
|
22 |
xgb_model = xgb.XGBRegressor()
|
23 |
+
xgb_model.load_model('xgbr1_exp3_model.json')
|
24 |
|
25 |
+
with open('pca_model1.pkl', 'rb') as f:
|
26 |
+
pca = pickle.load(f)
|
|
|
|
|
|
|
27 |
|
28 |
+
# with open('label_encoder_teams_xgbr1_exp3.pkl', 'rb') as f:
|
29 |
+
# label_encoder = pickle.load(f)
|
30 |
+
|
31 |
home_away_status = {'Home': 0, 'Away': 1}
|
32 |
df['Home/Away'] = df['Home/Away'].map(home_away_status)
|
33 |
+
|
34 |
+
df = pca.transform(df)
|
35 |
+
|
36 |
score = xgb_model.predict(df)
|
37 |
if score[0] < 0:
|
38 |
score = np.clip(score[0], a_min=0, a_max=None)
|
|
|
41 |
|
42 |
def predict_2(team, inning, venue, hits, errors, lob, runs, opp_team, opp_runs, opp_hits):
|
43 |
data = [team, opp_team, inning, venue, hits, opp_hits, errors, runs, opp_runs, lob]
|
44 |
+
|
45 |
+
df_main = pd.read_csv("Score_prediction_dataset_11th_July.csv")
|
46 |
+
df_main = df_main.drop(columns=['Final_Score', 'Opp_LOB'])
|
47 |
+
df_main = pd.get_dummies(df_main, columns=['Team_Name', 'Opposition_Team'])
|
48 |
+
|
49 |
df = pd.DataFrame([data], columns=["Team_Name", "Opposition_Team", "Inning", "Home/Away", "Hits", "Opp_Hits", "Errors", "Runs", "Opp_Runs", "LOB"])
|
50 |
+
df = pd.get_dummies(df, columns=['Team_Name', 'Opposition_Team'])
|
51 |
+
|
52 |
+
df = df.reindex(columns=df_main.columns, fill_value=0)
|
53 |
|
54 |
cat_model = CatBoostRegressor()
|
55 |
+
cat_model.load_model('catbr1_exp4_model.json')
|
56 |
|
57 |
+
# with open('label_encoder_teams_catbr1_exp1.pkl', 'rb') as f:
|
58 |
+
# label_encoder = pickle.load(f)
|
59 |
|
60 |
+
# df['Team_Name'] = label_encoder.transform(df['Team_Name'])
|
61 |
+
# df['Opposition_Team'] = label_encoder.transform(df['Opposition_Team'])
|
62 |
|
63 |
home_away_status = {'Home': 0, 'Away': 1}
|
64 |
df['Home/Away'] = df['Home/Away'].map(home_away_status)
|
65 |
+
|
66 |
+
with open('pca_model1.pkl', 'rb') as f:
|
67 |
+
pca = pickle.load(f)
|
68 |
+
|
69 |
+
df = pca.transform(df)
|
70 |
+
|
71 |
score = cat_model.predict(df)
|
72 |
if score[0] < 0:
|
73 |
score = np.clip(score[0], a_min=0, a_max=None)
|