-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
140 lines (116 loc) · 3.55 KB
/
app.py
File metadata and controls
140 lines (116 loc) · 3.55 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
from flask import Flask,render_template,request
import numpy as np
app = Flask(__name__)
import pickle
model = pickle.load(open('osi_knn', 'rb'))
@app.route("/",methods=['GET','POST'])
def hello_world():
return render_template("index.html")
def Encoding_Month(month):
num = 0
if month == 'February':
num=2
elif month == 'March'or month == 'April':
num=5
elif month == 'May':
num=6
elif month == 'June':
num=4
elif month == 'July':
num=3
elif month == 'August':
num=0
elif month == 'September':
num=9
elif month == 'October':
num=8
elif month == 'November':
num=7
elif month == 'Descember' or month=='January':
num=1
return num
def Encoding_Visitor(vis):
num = 0
if vis == 'Returning Visitor':
num = 2
elif vis == 'New Visitor':
num = 0
elif vis == 'Other':
num = 1
return num
def Encoding_Region(region):
num = 0
if region == 'United States':
num = 1
elif region == 'Germany':
num = 2
elif region == 'India':
num = 3
elif region == 'France':
num = 4
elif region == 'United Kingdom':
num = 5
elif region == 'Brazil':
num = 6
elif region == 'Italy':
num = 7
elif region == 'Austalia':
num = 8
elif region == 'Spain':
num = 9
return num
mean = [5228.289588354559,
1350.3003767343155,
2228.8511406021103,
1.6308603553860055,
0.04701054003755943,
15.070402452799382,
3.063447445035639,
5.232506776428069]
std = [33855.16236319768,
11714.049416369837,
15173.139612558776,
0.7571679042941348,
0.169662213903642,
29.5744024822749,
2.3508388396800353,
2.3483951485421475]
@app.route("/out",methods=['GET','POST'])
def Out():
return render_template('out.html')
@app.route("/features",methods=['GET','POST'])
def features():
if (request.method=='POST'):
browser = request.form.get('browser')
pro_page = request.form.get('pro_page')
pro_time = request.form.get('pro_time')
inf_page = request.form.get('inf_page')
inf_time = request.form.get('inf_time')
adm_page = request.form.get('adm_page')
adm_time = request.form.get('adm_time')
visType = request.form.get('visType')
spec_day = request.form.get('spec_day')
Region = request.form.get('Region')
pageValue = request.form.get('pageValue')
month = request.form.get('month')
pro_page_pr_time = float(pro_page)/(float(pro_time)+0.00001)
inf_page_pr_time = float(inf_page)/(float(inf_time)+0.00001)
adm_page_pr_time = float(adm_page)/(float(adm_time)+0.00001)
visType = Encoding_Visitor(visType)
Region = Encoding_Region(Region)
month = Encoding_Month(month)
points = [pro_page_pr_time,adm_page_pr_time,inf_page_pr_time,visType,spec_day,pageValue,Region,month]
da = [[float(i)] for i in points]
data = np.asarray(da).T
data = (data - mean)/std
output = model.predict(data)
if output:
color = "text-success"
messege = "Model predicts, The revenue will be Generated"
else:
color = "text-danger"
messege = "Model predicts revenue will not be generated"
return render_template('out.html',messege = messege, color=color)
return render_template('out.html')
if __name__ == '__main__':
app.run(debug=True)