Created
January 24, 2021 13:45
-
-
Save BenTenmann/c0b06d1813c6658c24ad8595182793eb to your computer and use it in GitHub Desktop.
tds_2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n_data_points = len(inputs) | |
train = int(n_data_points * 0.8) | |
validate = (n_data_points - train) // 2 | |
test = n_data_points - train - validate | |
# train the model over the specified number of epochs | |
for i in range(epochs): | |
err = 0 | |
for n in range(train): # iterate over the training set | |
z = np.array(inputs[n]) | |
t = int(np.sum(z) >= 0) # evaluates to 1 if True and 0 if False | |
x = np.append(z, -1) # add bias unit to input vector | |
w += epsilon * gradient_descent(t, w, x) # update weights | |
err += loss(t, f(x.dot(w))) # record error | |
ep_err.append(err/train) # average training error per-epoch | |
for n in range(train, train+validate): # validate | |
z = np.array(inputs[n]) | |
t = int(np.sum(z) >= 0) # evaluates to 1 if True and 0 if False | |
x = np.append(z, -1) | |
# note: no weights update | |
err += loss(t, f(x.dot(w))) | |
ep_err.append(err/validate) # average validation error per-epoch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment