# Ridge regression using stochastic gradient descent in Python

I am trying to implement a solution to Ridge regression in Python using Stochastic gradient descent as the solver. My code for SGD is as follows:

def fit(self, X, Y):
# Convert to data frame in case X is numpy matrix
X = pd.DataFrame(X)

# Prepend a column of 1s to the data for the intercept
X.insert(0, 'intercept', np.array([1.0]*X.shape[0]))

# Find dimensions of train
m, d = X.shape

# Initialize weights to random
beta = self.initializeRandomWeights(d)
beta_prev = None

epochs = 0
prev_error = None
while (epochs < self.nb_epochs):
print("## Epoch: " + str(epochs))
indices = range(0, m)
shuffle(indices)
for i in indices:   # Pick a training example from a randomly shuffled set
beta_prev = beta
xi = X.iloc[i]
errori = sum(beta*xi) - Y[i]        # Error[i] = sum(beta*x) - y = error of ith training example