Slide 12
Slide 12 text
• 3 : the algorithm receives the true label
of the instance
– use this label feedback to update
hypothesis for future trials
# initialize our model
w = [0.] * D # weights
n = [0.] * D # number of times we've encountered a feature
alpha = .1 # learning rate for sgd optimization
def update_w(w, n, x, p, y):
for i in x:
# alpha / (sqrt(n) + 1) is the adaptive learning rate heuristic
# (p - y) * x[i] is the current gradient
# note that in our case, if i in x then x[i] = 1
w[i] -= (p - y) * alpha / (sqrt(n[i]) + 1.)
n[i] += 1.
return w, n
Solution with 75 lines of Python Code