-
Notifications
You must be signed in to change notification settings - Fork 0
/
Final.py
82 lines (52 loc) · 1.72 KB
/
Final.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
from flask import Flask,render_template, request, flash
from selection_validator import ContactForm
import pandas as pd
import numpy as np
import pandas as pd
from sklearn import cross_validation,datasets, linear_model, metrics
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
app = Flask(__name__)
app.secret_key = 'development key'
@app.route('/')
def Index():
return render_template("index.html")
@app.route('/index.html')
def Front():
return render_template("index.html")
@app.route('/About.html')
def About():
return render_template("About.html")
@app.route('/Services.html')
def Services():
return render_template("Services.html")
@app.route('/Visualization.html')
def Visualization():
return render_template('Visualization.html')
@app.route('/Statistics.html')
def Statistics():
return render_template('Statistics.html')
@app.route('/Predict.html')
def Predicts():
return render_template('Predict.html')
@app.route('/Graph.html',methods = ['POST'])
def Graph():
Crime_type = request.form.get("type")
year = request.form.get("Predict_Year")
df = pd.read_csv("static/crime.csv")
X = df[['Year']]
y = df[[Crime_type]]
X_train,X_test,y_train,y_test = cross_validation.train_test_split(X,y,test_size=0.2)
regressor = LinearRegression()
regressor.fit(X_train,y_train)
accuracy = regressor.score(X_test,y_test)
accuracy = accuracy * 100
year = float(year)
X_test1 = np.array([year])
y_prediction1 = regressor.predict([X_test1])
return render_template('Graph.html',data = [Crime_type,year,accuracy,X_test1,y_prediction1])
@app.route('/D3_bar.html')
def BarChart():
return render_template("D3_bar.html")
if __name__=='__main__':
app.run(debug=True)