-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
81 lines (65 loc) · 3.13 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from flask import Flask, render_template, request
import jsonify
import requests
import pickle
import numpy as np
import pandas as pd
import sklearn
app = Flask(__name__)
outliers_lcap = pickle.load(open('object-instances/outliers_lcap.pkl', 'rb'))
outliers_ucap = pickle.load(open('object-instances/outliers_ucap.pkl', 'rb'))
missing_imputation = pickle.load(open('object-instances/missing_imputation.pkl', 'rb'))
model = pickle.load(open('models/RandomForestTuned2.pkl', 'rb'))
scaler = pickle.load(open('models/scaler.pkl', 'rb'))
@app.route('/', methods=['GET'])
def Home():
return render_template('index.html')
@app.route("/predict", methods=['POST'])
def predict():
if request.method == 'POST':
data_dict = {}
if request.form['FTI']=='':
data_dict['FTI'] = missing_imputation['FTI']
else:
data_dict['FTI'] = max(min(float(request.form['FTI']), outliers_ucap['FTI']), outliers_lcap['FTI'])
if request.form['T3']=='':
data_dict['T3'] = missing_imputation['T3']
else:
data_dict['T3'] = max(min(float(request.form['T3']), outliers_ucap['T3']), outliers_lcap['T3'])
if request.form['T4U']=='':
data_dict['T4U'] = missing_imputation['T4U']
else:
data_dict['T4U'] = max(min(float(request.form['T4U']), outliers_ucap['T4U']), outliers_lcap['T4U'])
if request.form['TSH']=='':
data_dict['TSH'] = missing_imputation['TSH']
else:
data_dict['TSH'] = max(min(float(request.form['TSH']), outliers_ucap['TSH']), outliers_lcap['TSH'])
if request.form['TT4']=='':
data_dict['TT4'] = missing_imputation['TT4']
else:
data_dict['TT4'] = max(min(float(request.form['TT4']), outliers_ucap['TT4']), outliers_lcap['TT4'])
if request.form['age']=='':
data_dict['age'] = missing_imputation['age']
else:
data_dict['age'] = max(min(int(request.form['age']), outliers_ucap['age']), outliers_lcap['age'])
data_dict['goitre'] = float(request.form['goitre'])
data_dict['hypopituitary'] = float(request.form['hypopituitary'])
data_dict['lithium'] = float(request.form['lithium'])
data_dict['pregnant'] = float(request.form['pregnant'])
data_dict['psych'] = float(request.form['psych'])
data_dict['sex'] = float(request.form['sex'])
data_dict['sick'] = float(request.form['sick'])
data_dict['thyroid_surgery'] = float(request.form['thyroid_surgery'])
data_dict['tumor'] = float(request.form['tumor'])
data_df = pd.DataFrame(columns = data_dict.keys(), index = [0])
for var in data_dict.keys():
data_df.loc[0,[var]] = data_dict[var]
prediction = model.predict(data_df)[0]
if prediction:
return render_template('index.html', prediction_text="You may have Thyroid Disease")
else:
return render_template('index.html', prediction_text="You may not have Thyroid Disease")
else:
return render_template('index.html')
if __name__=="__main__":
app.run(debug=True)