-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiments.py
156 lines (114 loc) · 3.77 KB
/
experiments.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
import pandas as pd
import numpy as np
import time
import matplotlib.pyplot as plt
from tree.base import DecisionTree
from metrics import *
np.random.seed(42)
num_average_time = 100
# Learn DTs
# ...
#
# Function to calculate average time (and std) taken by fit() and predict() for different N and P for 4 different cases of DTs
# ...
# Function to plot the results
# ..
# Function to create fake data (take inspiration from usage.py)
# ...
# ..other functions
""" Case: RIRO"""
learning_time = list()
predict_time = list()
for Ni in range(1,7):
for step in range(6,42):
N = Ni
P = step
X = pd.DataFrame(np.random.randn(N, P))
y = pd.Series(np.random.randn(N))
start_time = time.time()
tree = DecisionTree(criterion="information_gain")
tree.fit(X, y)
end_time = time.time()
learning_time.append(end_time-start_time)
start_time = time.time()
y_hat = tree.predict(X)
end_time = time.time()
predict_time.append(end_time-start_time)
plt.plot(list(learning_time))
plt.ylabel('RIRO : Fit time', fontsize=16)
plt.show()
plt.plot(list(predict_time))
plt.ylabel('RIRO : Predict time', fontsize=16)
plt.show()
""" Case: RIDO"""
learning_time = list()
predict_time = list()
for Ni in range(1,7):
for step in range(6,42):
N = Ni
P = step
X = pd.DataFrame(np.random.randn(N, P))
y = pd.Series(np.random.randint(P, size = N), dtype="category")
start_time = time.time()
tree = DecisionTree(criterion="information_gain")
tree.fit(X, y)
end_time = time.time()
learning_time.append(end_time-start_time)
start_time = time.time()
y_hat = tree.predict(X)
end_time = time.time()
predict_time.append(end_time-start_time)
plt.plot(list(learning_time))
plt.ylabel('RIDO : Fit time', fontsize=16)
plt.show()
plt.plot(list(predict_time))
plt.ylabel('RIDO : Predict time', fontsize=16)
plt.show()
""" Case: DIRO"""
# learning_time = list()
# predict_time = list()
# for Ni in range(1,7):
# for step in range(6,42):
# N = Ni
# P = step
# X = pd.DataFrame({i:pd.Series(np.random.randint(P, size = N), dtype="category") for i in range(5)})
# y = pd.Series(np.random.randn(N))
# start_time = time.time()
# tree = DecisionTree(criterion="information_gain")
# tree.fit(X, y)
# end_time = time.time()
# learning_time.append(end_time-start_time)
# start_time = time.time()
# y_hat = tree.predict(X)
# end_time = time.time()
# predict_time.append(end_time-start_time)
# plt.plot(list(learning_time))
# plt.ylabel('DIRO : Fit time', fontsize=16)
# plt.show()
# plt.plot(list(predict_time))
# plt.ylabel('DIRO : Predict time', fontsize=16)
# plt.show()
""" Case: DIDO"""
learning_time = list()
predict_time = list()
for Ni in range(1,7):
for step in range(6,42):
N = Ni
P = step
X = pd.DataFrame({i:pd.Series(np.random.randint(P, size = N), dtype="category") for i in range(5)})
y = pd.Series(np.random.randint(P, size = N) , dtype="category")
start_time = time.time()
tree = DecisionTree(criterion="information_gain")
tree.fit(X, y)
end_time = time.time()
learning_time.append(end_time-start_time)
start_time = time.time()
y_hat = tree.predict(X)
end_time = time.time()
predict_time.append(end_time-start_time)
plt.plot(list(learning_time))
plt.ylabel('DIDO : Fit time', fontsize=16)
plt.show()
plt.plot(list(predict_time))
plt.ylabel('DIDO : Predict time', fontsize=16)
plt.show()