-
Notifications
You must be signed in to change notification settings - Fork 61
/
04-fire.py
47 lines (36 loc) · 860 Bytes
/
04-fire.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
import pickle
import sqlite3
import pandas as pd
import fire
con = sqlite3.connect("data/basketball.db")
with open("pickles/pipe.pkl", "rb") as f:
pipe = pickle.load(f)
def fetch_player_data(name):
player = pd.read_sql(
f"""
select
*
from players
where name = '{name}'
order by date desc
limit 2
""",
con,
).sort_values("date", ascending=False)
return player
def prep_data(player):
X_new = pd.DataFrame(
{
"position": [player.position[0]],
"points_1": [player.points[0]],
"points_2": [player.points[1]],
}
)
return X_new
def predict(player):
X = fetch_player_data(player)
X = prep_data(X)
X = round(pipe.predict(X)[0], 2)
return X
if __name__ == "__main__":
fire.Fire(predict)