Loop 1: (Stochastic - expected faster)
for i in range(len(data)):
x = data[i]
for t in range(0, m):
theta[t] -= my_lambda * (np.dot(theta, x) - y[i]) * x[t]
vs Loop 2: (Batch - expected slower)
for t in range(0, m):
temp = 0
for i in range(len(data)):
x = data[i]
temp += (np.dot(theta, x) - y[i]) * x[t]
theta[t] = theta[t] - my_lambda * temp / M
But my batch is much much much faster - One iteration Elapsed time 0.025356054306 vs my stochastic is really slower - One iteration Elapsed time 1.0576338768
Here my m is 13 and data is around 500 tuples. Can anyone tell me why so? Or where did I mess up for stochastic? Thanks!
EDIT 1:
data = [[], [], ...]
data = [record1, record2 ...]
record = [1, x1, x2, ... , x_m]
theta is vector
theta = np.zeros(m+1) //np is numpy