-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
83 lines (64 loc) · 2.96 KB
/
Copy pathapp.py
File metadata and controls
83 lines (64 loc) · 2.96 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
import pandas as pd
from sklearn import linear_model
import tkinter as tk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
df = pd.read_csv("HDFC.csv")
X = df[['Open','Close']] # here we have 2 variables for multiple regression. If you just want to use one variable for simple linear regression, then use X = df['Interest_Rate'] for example.Alternatively, you may add additional variables within the brackets
Y = df['Turnover']
# with sklearn
regr = linear_model.LinearRegression()
regr.fit(X, Y)
print('Intercept: \n', regr.intercept_)
print('Coefficients: \n', regr.coef_)
# tkinter GUI
root= tk.Tk()
canvas1 = tk.Canvas(root, width = 500, height = 300)
canvas1.pack()
# with sklearn
Intercept_result = ('Intercept: ', regr.intercept_)
label_Intercept = tk.Label(root, text=Intercept_result, justify = 'center')
canvas1.create_window(260, 220, window=label_Intercept)
# with sklearn
Coefficients_result = ('Coefficients: ', regr.coef_)
label_Coefficients = tk.Label(root, text=Coefficients_result, justify = 'center')
canvas1.create_window(260, 240, window=label_Coefficients)
# New_Interest_Rate label and input box
label1 = tk.Label(root, text='Type Open Rate: ')
canvas1.create_window(100, 100, window=label1)
entry1 = tk.Entry (root) # create 1st entry box
canvas1.create_window(270, 100, window=entry1)
# New_Unemployment_Rate label and input box
label2 = tk.Label(root, text=' Type Close Rate: ')
canvas1.create_window(120, 120, window=label2)
entry2 = tk.Entry (root) # create 2nd entry box
canvas1.create_window(270, 120, window=entry2)
def values():
global Open #our 1st input variable
Open = float(entry1.get())
global Close #our 2nd input variable
Close = float(entry2.get())
Prediction_result = ('Predicted Stock Turnover: ', regr.predict([[Open ,Close]]))
label_Prediction = tk.Label(root, text= Prediction_result, bg='orange')
canvas1.create_window(260, 280, window=label_Prediction)
button1 = tk.Button (root, text='Predict Stock Turnover Price',command=values, bg='orange') # button to call the 'values' command above
canvas1.create_window(270, 150, window=button1)
#plot 1st scatter
figure3 = plt.Figure(figsize=(5,4), dpi=100)
ax3 = figure3.add_subplot(111)
ax3.scatter(df['Open'].astype(float),df['Turnover'].astype(float), color = 'r')
scatter3 = FigureCanvasTkAgg(figure3, root)
scatter3.get_tk_widget().pack(side=tk.RIGHT, fill=tk.BOTH)
ax3.legend(['Turnover'])
ax3.set_xlabel('Open')
ax3.set_title('Open Vs. Turnover')
#plot 2nd scatter
figure4 = plt.Figure(figsize=(5,4), dpi=100)
ax4 = figure4.add_subplot(111)
ax4.scatter(df['Close'].astype(float),df['Turnover'].astype(float), color = 'g')
scatter4 = FigureCanvasTkAgg(figure4, root)
scatter4.get_tk_widget().pack(side=tk.RIGHT, fill=tk.BOTH)
ax4.legend(['Turnover'])
ax4.set_xlabel('Close')
ax4.set_title('Close Vs. Turnover')
root.mainloop()