-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
103 lines (86 loc) · 3.7 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
import numpy as np
import pandas as pd
#Importing Visualization libraries
import sklearn
import seaborn as sns
import matplotlib.pyplot as plt
#Importing Classes from the python files
from information import Information
from preprocessing import Pre_Processing
from plots import Plots
from visualization import Visualization
from kMeansClustering import KMeans_clustering
#Importing from flask
from flask import Flask, render_template, request, send_file
import jsonify
import requests
from flask import Response
PEOPLE_FOLDER = os.path.join('static', 'sub')
df= pd.read_csv('cars.csv')
df["Ex-Showroom_Price"] = df["Ex-Showroom_Price"].str.replace(r'.* ([\d,]+)+$', r'\1',regex=True).str.replace(',', '',regex=True).astype('int32')
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = PEOPLE_FOLDER
@app.route("/information")
def information():
data=Information(df)
dataset_shape,dataTypes,data_head,data_tail,data_describe=data.info()
total_missing,missing_value,percentage_missing_value = data.total_missing_values()
data2=Pre_Processing(df,percentage_missing_value)
drop_head=data2.drop_column()
fill_head=data2.fill_missing_values()
dummy=data2.dummies()
return render_template('index.html',shape=dataset_shape,dtypes=dataTypes,head=[data_head.to_html(classes='HEAD')],
tail=[data_tail.to_html(classes='TAIL')],desc=[data_describe.to_html(classes='HEAD')],
totalMis=total_missing,MisVal=missing_value,cent=percentage_missing_value,
dhead=[drop_head.to_html(classes='DHEAD')],fhead=[fill_head.to_html(classes='FHEAD')],dum=[dummy.to_html(classes='DHEAD')])
data=Information(df)
total_missing,missing_value,percentage_missing_value = data.total_missing_values()
data2=Pre_Processing(df,percentage_missing_value)
drop_head=data2.drop_column()
fill_head=data2.fill_missing_values()
@app.route("/plots",methods=['POST'])
def plots():
if request.method=="POST":
col=request.form['Column']
data=Plots(df,col)
fig=data.bar_plot()
full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'bar.png')
return render_template("index.html", a = full_filename)
@app.route("/boxPlot",methods=['POST'])
def boxPlot():
if request.method=="POST":
cl=request.form['Col']
data=Plots(df,cl)
fig=data.box_plot()
full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'box.png')
return render_template("index.html", b = full_filename)
@app.route("/barPlot",methods=['POST'])
def barPlot():
if request.method=="POST":
x=request.form['x']
y=request.form['y']
data = Visualization(df,x,y)
fig=data.bar_chart()
full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'bar2.png')
return render_template("index.html", c = full_filename)
@app.route("/scatterPlot",methods=['POST'])
def scatterPlot():
if request.method=="POST":
x=request.form['xAxis']
y=request.form['yAxis']
data = Visualization(df,x,y)
fig=data.scatter_chart()
full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'scatter2.png')
return render_template("index.html", d= full_filename)
@app.route("/optimalK")
def optimalK():
data=KMeans_clustering(df)
scaled_feature=data.scaling_features()
fig=data.sum_square_error()
full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'elbowPlot.png')
g=data.kmean()
file = os.path.join(app.config['UPLOAD_FOLDER'], 'clustering.png')
return render_template("index.html", scaled=[scaled_feature.to_html(classes='SHEAD')], e= full_filename,f= file)
if __name__ == '__main__':
app.run(debug = True)