Last active
January 14, 2024 23:38
-
-
Save TupotaValentyn/9a8c8e80c899ee53f97b05451a33764f to your computer and use it in GitHub Desktop.
Neural Network sample 1
This file contains hidden or 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
count = 10 | |
coefficient = 2 | |
inputs = [n + 1 for n in range(count)] | |
targets = [i * coefficient for i in inputs] | |
EPOACH = 25 | |
w = 0.1 | |
learning_rate = 0.1 | |
def predict(i): | |
return w * i | |
for _ in range(EPOACH): | |
pred = [predict(i) for i in inputs] | |
errors = [t - p for p, t in zip(pred, targets)] | |
cost = sum(errors) / len(targets) | |
print(f"Weight: {w:.2f}, Cost: {cost:.2f}") | |
w += learning_rate * cost | |
# Network Tests | |
test_inputs = [5, 6, 7, 8, 9] | |
test_targets = [10, 12, 14, 16, 18] | |
print(f"W: {w:.2f}") | |
pred = [predict(i) for i in test_inputs] | |
for i, t, p in zip(test_inputs, test_targets, pred): | |
print(f"inputs: {i}, targets: {t}, pred: {p:.4f}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment