-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathml_projects.py
231 lines (176 loc) · 7.83 KB
/
ml_projects.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# Importing Flask essentials
from flask import Flask, request, render_template, redirect, url_for
# Importing Pandas for Data Reading
import pandas as pd
# Importing Numpy for Array Manipulation
import numpy as np
# Importing own modules
from py_modules import data_extraction as de
# Import pickle module to load models
import pickle
# Flask App
ml_app = Flask(__name__)
# Reading my social links data
social = pd.read_csv('data/social-media-links.csv')
# Extraction of social link data
social_data = de.get_social_link_data(social)
# Counting number of Data
number_of_links = len(social_data[0])
# Root or Home page - About Me
@ml_app.route('/')
def all_projects():
# Reading ML_Projects data
ml_projects = pd.read_csv('data/ML_Projects.csv')
# Calculating number of projects
number_of_projects = ml_projects.shape[0]
# Calculating rows for UI
rows = (number_of_projects // 3) + 1
# Extracting Machine Learning Projects Data
ml_projects_data = de.get_ml_projects_data(ml_projects)
# Extracting Libraries links
libraries = ml_projects_data[9]
libraries_used = [[str(library) for library in rows.split('|')] for rows in libraries]
# Extracting Technologies
technologies = ml_projects_data[11]
technologies_used = [[str(technology) for technology in rows.split('|')] for rows in technologies]
# Extracting Frame works
frameworks = ml_projects_data[10]
frameworks_used = [[str(framework) for framework in rows.split('|')] for rows in frameworks]
# Extracting Tools / IDE
tools = ml_projects_data[12]
tools_used = [[str(tool) for tool in rows.split('|')] for rows in tools]
return render_template('all_projects.html',
social_data=social_data,
n = number_of_links,
ml_projects_data = ml_projects_data,
rows = rows,
libraries_used = libraries_used,
technologies_used = technologies_used,
frameworks_used = frameworks_used,
tools_used = tools_used)
# Boston House Price Predictor
@ml_app.route('/boston_house_price_predictor', methods = ['POST', 'GET'])
def boston_house_price_predictor():
if request.method == "POST":
# Getting Input Data from UI
'LSTAT', 'RM', 'PTRATIO', 'INDUS', 'TAX', 'NOX'
lstat = float(request.form['lstat'])
rm = float(request.form['rm'])
ptratio = float(request.form['ptratio'])
indus = float(request.form['indus'])
tax = float(request.form['tax'])
nox = float(request.form['nox'])
# Forming an input array
input_array = [[lstat, rm, ptratio, indus, tax, nox]]
# Loading Loan Status Predictor Model
boston_house_price_predictor = pickle.load(open('models/boston_house_price_predictor.pkl', 'rb'))
# Prediction
price_predicted = np.round(boston_house_price_predictor.predict(input_array), 2)
# Predicting Probability
# predict_proba = boston_house_price_predictor.predict_proba(input_array) * 100
return render_template('boston_house_price_predictor.html',
social_data = social_data,
n = number_of_links,
price_predicted = price_predicted,
input_array = input_array)
return render_template('boston_house_price_predictor.html',
social_data = social_data,
n = number_of_links)
# Loan Status Predictor
@ml_app.route('/loan_status_predictor', methods = ['POST', 'GET'])
def loan_status_predictor():
if request.method == "POST":
# Getting Input Data from UI
credit_history = float(request.form['credit_history'])
loan_amount = float(request.form['loan_amount'])
applicant_income = float(request.form['applicant_income'])
coapplicant_income = float(request.form['coapplicant_income'])
dependents = float(request.form['dependents'])
# Forming an input array
input_array = [[credit_history, loan_amount, applicant_income, coapplicant_income, dependents]]
# Loading Loan Status Predictor Model
loan_status_predictor_model = pickle.load(open('models/loan_status_predictor.pkl', 'rb'))
# Prediction
status_predicted = loan_status_predictor_model.predict(input_array)
# Predicting Probability
predict_proba = loan_status_predictor_model.predict_proba(input_array) * 100
return render_template('loan_status_predictor.html',
social_data = social_data,
n = number_of_links,
status_predicted = status_predicted,
predict_proba = predict_proba)
return render_template('loan_status_predictor.html',
social_data = social_data,
n = number_of_links)
# Iris Species Classifier
@ml_app.route('/iris_species_classifier', methods = ['POST', 'GET'])
def iris_species_classifier():
if request.method == 'POST':
# Getting Data from UI
petal_length = float(request.form['petal_length'])
petal_width = float(request.form['petal_width'])
# Forming an Input Array
input_array = [[petal_length, petal_width]]
# Loading Iris Species Classifier Model
iris_species_classifier_model = pickle.load(open('models/iris_species_classifier.pkl', 'rb'))
# Prediction
iris_predicted = iris_species_classifier_model.predict(input_array)
# Predicting Probaility
predict_proba = iris_species_classifier_model.predict_proba(input_array) * 100
return render_template('iris_species_classifier.html',
social_data = social_data,
n = number_of_links,
iris_predicted = iris_predicted,
predict_proba = predict_proba)
return render_template('iris_species_classifier.html',
social_data = social_data,
n = number_of_links)
# Gender Classifier
@ml_app.route('/gender_classifier', methods = ['POST', 'GET'])
def gender_classifier():
if request.method == 'POST':
# Getting Data from UI
height = float(request.form['height'])
weight = float(request.form['weight'])
# Forming an Input Array
input_array = [[height, weight]]
# Loading Gender Classifier Model
gender_classifier_model = pickle.load(open('models/gender_classifier.pkl', 'rb'))
# Prediction
gender_predicted = gender_classifier_model.predict(input_array)
# Predicting Probaility
predict_proba = gender_classifier_model.predict_proba(input_array) * 100
return render_template('gender_classifier.html',
social_data = social_data,
n = number_of_links,
gender_predicted = gender_predicted,
predict_proba = predict_proba)
return render_template('gender_classifier.html',
social_data = social_data,
n = number_of_links)
# Weight Predictor
@ml_app.route('/weight_predictor', methods = ['POST', 'GET'])
def weight_predictor():
if request.method == 'POST':
# Getting Data from UI
gender = float(request.form['gender'])
height = float(request.form['height'])
# Forming an Input Array
input_array = [[height, gender]]
# Loading Weight Predictor Model
weight_predictor_model = pickle.load(open('models/weight_predictor.pkl', 'rb'))
# Prediction
weight_predicted = round(weight_predictor_model.predict(input_array)[0], 2)
# Predicting Probaility
# predict_proba = weight_predictor_model.predict_proba(input_array) * 100
return render_template('weight_predictor.html',
social_data = social_data,
n = number_of_links,
weight_predicted = weight_predicted,
input_array = input_array)
return render_template('weight_predictor.html',
social_data = social_data,
n = number_of_links)
# App Launcher
if __name__ == '__main__':
ml_app.run(debug = True, port = 3000)