-
Notifications
You must be signed in to change notification settings - Fork 0
/
q8_compare_time.py
118 lines (84 loc) · 2.35 KB
/
q8_compare_time.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
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from linearRegression.linearRegression import LinearRegression
import time
"""Heat map plots"""
import seaborn as sns
sns.set_theme()
grad = []
norm = []
c = []
for N in range (20,200,10):
tempg = []
tempn = []
for P in range(5,20,2):
np.random.seed(P)
X = pd.DataFrame(np.random.randint(0,100,size=(N, P)))
# print(X)
y = pd.Series(np.random.randn(N))
LR = LinearRegression(fit_intercept=True)
# c.append([N,P])
start_time = time.time()
LR.fit_vectorised(X, y, batch_size=2)
end_time = time.time()
tempg.append(end_time-start_time)
# start_time = time.time()
# LR.fit_normal(X, y)
# end_time = time.time()
# tempn.append(end_time-start_time)
grad.append(tempg)
# norm.append(tempn)
# corr = pd.DataFrame(norm)
corr = pd.DataFrame(grad)
fig, ax = plt.subplots(figsize=(11, 9))
sns.heatmap(corr)
yticks = [N for N in range (20,200,10)]
xticks = [P for P in range(5,20,2)]
plt.yticks(plt.yticks()[0], labels=yticks, rotation=0)
plt.xticks(plt.xticks()[0], labels=xticks)
plt.show()
""""""
"""Normal plt plots"""
# a = []
# b = []
# c = []
# for i in range (10,200):
# N = 15
# X = pd.DataFrame(np.random.randn(N, i))
# y = pd.Series(np.random.randn(N))
# LR = LinearRegression(fit_intercept=True)
# c.append(i)
# start_time = time.time()
# LR.fit_vectorised(X, y,batch_size=2)
# end_time = time.time()
# a.append(end_time-start_time)
# start_time = time.time()
# LR.fit_normal(X, y)
# end_time = time.time()
# b.append(end_time-start_time)
# plt.plot(c,a,label = 'Gradient Descent')
# plt.plot(c,b,label = 'Normal Equation')
# plt.legend(loc = 'best')
# plt.show()
# a = []
# b = []
# c = []
# for i in range (10,10000,10):
# X = pd.DataFrame(np.random.randn(i, 9))
# y = pd.Series(np.random.randn(i))
# LR = LinearRegression(fit_intercept=True)
# c.append(i)
# start_time = time.time()
# LR.fit_vectorised(X, y,batch_size=2)
# end_time = time.time()
# a.append(end_time-start_time)
# start_time = time.time()
# LR.fit_normal(X, y)
# end_time = time.time()
# b.append(end_time-start_time)
# plt.plot(c,a,label = 'Gradient Descent')
# plt.plot(c,b,label = 'Normal Equation')
# plt.legend(loc = 'best')
# plt.show()
""""""