Добрый вечер, пара вопросов насчет вот этой функции, вопросы помечены в комментах:
def loss(self, X_batch, y_batch, reg):
"""Logistic Regression loss function
Inputs:
X: N x D array of data. Data are D-dimensional rows
y: 1-dimensional array of length N with labels 0-1, for 2 classes
Returns:
a tuple of:
loss as single float
gradient with respect to weights w; an array of same shape as w
"""
dw = np.zeros_like(self.w) # initialize the gradient as zero
loss = 0
Compute loss and gradient. Your code should not contain python loops.
pred = self.predict(X_batch)
loss = hl(y_batch , pred) #hamming function
dw = X_batch.transpose() * (pred - y_batch).transpose()
dw /= X_batch.shape[0]
# Right now the loss is a sum over all training examples, but we want it
# to be an average instead so we divide by num_train.
# Note that the same thing must be done with gradient.
<-----Что здесь вообще надо сделать и зачем это??? Почему моя ошибка - это сумма по всем выборкам?
# Add regularization to the loss and gradient.
# Note that you have to exclude bias term in regularization.
<--------------Как исключить "термин смещения"?
loss *= reg
dw *= reg
return loss, dw
Добрый вечер, пара вопросов насчет вот этой функции, вопросы помечены в комментах: def loss(self, X_batch, y_batch, reg): """Logistic Regression loss function Inputs:
Compute loss and gradient. Your code should not contain python loops.
<-----Что здесь вообще надо сделать и зачем это??? Почему моя ошибка - это сумма по всем выборкам?