-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
78 lines (60 loc) · 2.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from flask import Flask
from flask import render_template
from flask import request
from typing import Optional, Dict, Any, Union
from ChurnModel import ChurnModel as cm
import pandas as pd
app = Flask(__name__)
model = cm()
@app.route("/")
def hello():
classifiers = model.classifiers
return render_template('app.html', classifiers=classifiers)
@app.route("/classifier", methods=['get'])
def getClassifier():
message = "Select Classifier Type"
classifiers = model.classifiers
return render_template('app.html', classifiers=classifiers)
@app.route("/classifier", methods=['post'])
def postClassifier():
selected_classifier = request.form.get("classifier")
print(selected_classifier)
res = model.train(selected_classifier)
if len(res) == 0:
message = "training error"
classifiers = model.classifiers
return render_template('app.html', classifiers=classifiers, message=message)
score = res['score']
predicted_score = res['predicted_score']
confusion_matrix = pd.DataFrame(res['confusion_matrix']).to_html()
return render_template('train_result.html', selected_classifier=selected_classifier, score=score,
confusion_matrix=confusion_matrix,
predicted_score=predicted_score)
@app.route("/predict", methods=['get'])
def getPredict():
labels = model.getLabels()
return render_template('predict.html', labels=labels)
@app.route("/predict", methods=['post'])
def postPredict():
checks = {
'MonthlyCharges': [float(request.form.get("MonthlyCharges"))],
'SeniorCitizen': [float(request.form.get("SeniorCitizen"))],
'Dependents': [request.form.get("Dependents")],
'PhoneService': [request.form.get("PhoneService")],
'MultipleLines': [request.form.get("MultipleLines")],
'InternetService': [request.form.get("InternetService")],
'OnlineSecurity': [request.form.get("OnlineSecurity")],
'OnlineBackup': [request.form.get("OnlineBackup")],
'TechSupport': [request.form.get("TechSupport")],
'StreamingTV': [request.form.get("StreamingTV")],
'StreamingMovies': [request.form.get("StreamingMovies")],
'PaperlessBilling': [request.form.get("PaperlessBilling")]
}
if model.predict(checks) == 1:
message = "You clint will churn"
else:
message = "Your clint will not churn"
labels = model.getLabels()
return render_template('predict.html', labels=labels, message=message)
if __name__ == "__main__":
app.run()