I'm studiyng Adaline SGD method and I have some questions about my code (I will not put the whole algorithm for how extensive it is):
def __init__(self, eta=0.01, n_iter=50, shuffle=True, random_state =None) :
self.eta = eta
self.n_iter=n_iter
self.w_initialized=False
self.shuffle=True
self.random_state = random_state
def partial_fit(self,X,y):
"""Fit training data without reinitializing the weights"""
if not self.w_initialized:
self._initialize_weights(X.shape[1])
if y.ravel().shape[0]>1:
for xi, target in zip(X,y):
self._update_weights(xi, target)
def _shuffle(self,X,y):
"""Suffle training data"""
r=self.rgen.permutation(len(y))
return X[r], y[r]
def _initialize_weights(self,m):
"""Initialize weights to small random numbers"""
self.rgen= np.random.RandomState(self.random_state)
self.w_=self.rgen.normal(loc= 0.0, scale= 0.01, size = 1+m)
self.w_initialized=True
Why is
self.w_initializedset toFalsein the begginning indef __init__(self, eta=0.01, n_iter=50, shuffle=True, random_state =None)and later toTrueindef _initialize_weights(self,m)at the end? I don't understand how it works.Why in
r=self.rgen.permutation(len(y))it is not written...len(y)+1to cover the whole list?. (Note: On the next line, inX[r], y[r]I assume that returns the same vectors alternately randomized, if I'm wrong let me know)What does
mvariable inself.w_=self.rgen.normal(loc= 0.0, scale= 0.01, size = 1+m)do?. I know the meaning ofsize,but ,what is the result after adding m to 1?
Let me know if more context is needed. Sorry if my english is not perfect.