I hereby claim:
- I am bobbywlindsey on github.
- I am bobbylindsey (https://keybase.io/bobbylindsey) on keybase.
- I have a public key ASDhPbagCzR47qYnqzdc76WQ-KqheCkZRS_v8qgjmwLB1Ao
To claim this, I am signing this object:
weights = initialize_weights(train_data.shape[1]) | |
for epoch in range(3): | |
sum_of_squared_errors = 0.0 | |
for sample in range(train_data.shape[0]): | |
vector = train_data.loc[sample].values | |
label = train_label.loc[sample] | |
if label == 0: label = -1 | |
prediction = predict(vector, weights, 'sign') | |
error = label - prediction | |
sum_of_squared_errors += error**2 |
weights = initialize_weights(train_data.shape[1]) | |
for epoch in range(3): | |
sum_of_squared_errors = 0.0 | |
for sample in range(train_data.shape[0]): | |
vector = train_data.loc[sample].values | |
label = train_label.loc[sample] | |
if label == 0: label = -1 | |
prediction = predict(vector, weights, 'sign') | |
error = label - prediction | |
sum_of_squared_errors += error**2 |
weights = initialize_weights(train_data.shape[1]) | |
for epoch in range(3): | |
sum_of_squared_errors = 0.0 | |
for sample in range(train_data.shape[0]): | |
vector = train_data.loc[sample].values | |
label = train_label.loc[sample] | |
prediction = predict(vector, weights, 'step') | |
error = label - prediction | |
sum_of_squared_errors += error**2 | |
weights = weights + error * vector |
weights = initialize_weights(train_data.shape[1]) | |
sum_of_squared_errors = 0.0 | |
for sample in range(train_data.shape[0]): | |
vector = train_data.loc[sample].values | |
label = train_label.loc[sample] | |
prediction = predict(vector, weights, 'step') | |
error = label - prediction | |
sum_of_squared_errors += error**2 | |
weights = weights + error * vector | |
print(f'SSE: {sum_of_squared_errors}') |
weights = initialize_weights(train_data.shape[1]) | |
vector = train_data.loc[0].values | |
label = train_label.loc[0] | |
prediction = predict(vector, weights, 'step') | |
error = label - prediction | |
print(f'Prediction: {prediction}, Label: {label}, Error: {error}') |
def activation(x, function_name): | |
if function_name == 'step': | |
return step(x) | |
elif function_name == 'sign': | |
return sign(x) | |
else: | |
raise NotImplementedError | |
def initialize_weights(num_columns): |
train_data = pd.DataFrame(data = data, index=list(range(len(data))), columns=['X_1', 'X_2', 'label']) | |
# Don't forget to add a vector of 1s for the bias weight | |
train_data['bias'] = np.repeat(1.0, train_data.shape[0]) | |
train_label = train_data.label | |
train_data = train_data[[each for each in train_data.columns if each != 'label']] | |
train_data.head() |
import pandas as pd | |
import numpy as np | |
data = [[2.7810836,2.550537003,0], | |
[1.465489372,2.362125076,0], | |
[3.396561688,4.400293529,0], | |
[1.38807019,1.850220317,0], | |
[3.06407232,3.005305973,0], | |
[7.627531214,2.759262235,1], | |
[5.332441248,2.088626775,1], |
def sign(x): | |
if x > 0: | |
return 1.0 | |
elif x < 0: | |
return -1.0 | |
else: | |
return 0.0 | |
def step(x): |
I hereby claim:
To claim this, I am signing this object: