[81a4e3]: / request.py

Download this file

32 lines (23 with data), 777 Bytes

 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
import requests
import pandas as pd
from sklearn.metrics import f1_score
from utils import Preprocess
import numpy as np
df = pd.read_excel('dataset.xlsx',engine='openpyxl')
df.drop(['Unnamed: 0', 'visit id'], axis=1, inplace=True)
# df = df[:1000]
json_data = df.to_json(orient='records')
# Send POST request with JSON data
url = "http://127.0.0.1:8000/predict/"
response = requests.post(url, json=json_data)
# Print the response (predictions)
response = response.json()
predictions = response['predictions']
pre = Preprocess(df, 0, 0, 0)
df = pre._mapping(df)
y_pre = np.array(predictions)
y_true = df['target label / yes no'].fillna(0)
y_true = y_true.values.astype(int)
np.unique(y_true,return_counts=True)
f1 = f1_score(y_true, y_pre,average='weighted')
print(f1)