-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
63 lines (49 loc) · 1.75 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
from flask import Flask,render_template,url_for,request
from flask_material import Material
# EDA PKg
import pandas as pd
import numpy as np
# ML Pkg
from sklearn.externals import joblib
app = Flask(__name__)
Material(app)
@app.route('/')
def index():
return render_template("index.html")
@app.route('/preview')
def preview():
df = pd.read_csv("data/iris.csv")
return render_template("preview.html",df_view = df)
@app.route('/',methods=["POST"])
def analyze():
if request.method == 'POST':
petal_length = request.form['petal_length']
sepal_length = request.form['sepal_length']
petal_width = request.form['petal_width']
sepal_width = request.form['sepal_width']
model_choice = request.form['model_choice']
# Clean the data by convert from unicode to float
sample_data = [sepal_length,sepal_width,petal_length,petal_width]
clean_data = [float(i) for i in sample_data]
# Reshape the Data as a Sample not Individual Features
ex1 = np.array(clean_data).reshape(1,-1)
# ex1 = np.array([6.2,3.4,5.4,2.3]).reshape(1,-1)
# Reloading the Model
if model_choice == 'logitmodel':
logit_model = joblib.load('data/logit_model_iris.pkl')
result_prediction = logit_model.predict(ex1)
elif model_choice == 'knnmodel':
knn_model = joblib.load('data/knn_model_iris.pkl')
result_prediction = knn_model.predict(ex1)
elif model_choice == 'svmmodel':
knn_model = joblib.load('data/svm_model_iris.pkl')
result_prediction = knn_model.predict(ex1)
return render_template('index.html', petal_width=petal_width,
sepal_width=sepal_width,
sepal_length=sepal_length,
petal_length=petal_length,
clean_data=clean_data,
result_prediction=result_prediction,
model_selected=model_choice)
if __name__ == '__main__':
app.run(debug=True)