Created
December 20, 2017 23:46
-
-
Save hackintoshrao/f0d8a6de477170693a4008e86abe9132 to your computer and use it in GitHub Desktop.
OR perceptron implementation
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
| import pandas as pd | |
| # Set weight1, weight2, and bias so that only the inputs 1,1 falls into positive area | |
| weight1 = 2.0 | |
| weight2 = 2.0 | |
| bias = -1 | |
| # Inputs and otutputs | |
| test_inputs = [(0, 0), (0, 1), (1, 0), (1, 1)] | |
| correct_outputs = [False, False, False, True] | |
| outputs = [] | |
| # Generate and check output | |
| for test_input, correct_output in zip(test_inputs, correct_outputs): | |
| linear_combination = weight1 * test_input[0] + weight2 * test_input[1] + bias | |
| output = int(linear_combination >= 0) | |
| is_correct_string = 'Yes' if output == correct_output else 'No' | |
| outputs.append([test_input[0], test_input[1], linear_combination, output, is_correct_string]) | |
| # Print output | |
| output_frame = pd.DataFrame(outputs, columns=['Input 1', ' Input 2', ' Linear Combination', ' Activation Output', ' Is Correct']) | |
| print(output_frame.to_string(index=False)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment