-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
54 lines (45 loc) · 1.52 KB
/
app.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
import pandas as pd
import numpy as np
from flask_cors import CORS
from sklearn.linear_model import LogisticRegression
import pickle
from flask import Flask ,request, jsonify
app = Flask(__name__)
CORS(app)
'''
Train Model before starting Up the Server
'''
def data_split(data, ratio):
np.random.seed(42)
shuffled = np.random.permutation(len(data))
test_set_size = int(len(data)*ratio)
test_indices = shuffled[:test_set_size]
train_indices = shuffled[test_set_size:]
return data.iloc[train_indices], data.iloc[test_indices]
df = pd.read_csv('data1.csv')
train, test = data_split(df, 0.3)
X_train = train[['fever','age','tiredness','cough','feverDays']].to_numpy()
X_test = test[['fever','age','tiredness','cough','feverDays']].to_numpy()
Y_train = train[['infectionProb']].to_numpy().reshape(len(train),)
Y_test = test[['infectionProb']].to_numpy().reshape(len(test),)
clf = LogisticRegression()
clf.fit(X_train, Y_train)
@app.route('/', methods = ["GET","POST"])
def check_result():
try:
inputFeatures = [
int(request.args.get('fever')),
int(request.args.get('age')),
int(request.args.get('tiredness')),
int(request.args.get('cough')),
int(request.args.get('feverDays')),
]
infProb = clf.predict_proba([inputFeatures])[0][1]
return jsonify({'result':infProb*100})
except:
return jsonify({'result':'INVALID'})
print
# print(inputFeatures)
if __name__ == '__main__':
print("Server Up")
app.run()