Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. # TODO: Set weight1, weight2, and bias
  4. weight1 = 70
  5. weight2 = 30
  6. bias = 040
  7.  
  8.  
  9. # DON'T CHANGE ANYTHING BELOW
  10. # Inputs and outputs
  11. test_inputs = [(0, 0), (0, 1), (1, 0), (1, 1)]
  12. correct_outputs = [False, False, False, True]
  13. outputs = []
  14.  
  15. # Generate and check output
  16. for test_input, correct_output in zip(test_inputs, correct_outputs):
  17.     linear_combination = weight1 * test_input[0] + weight2 * test_input[1] + bias
  18.     output = int(linear_combination >= 0)
  19.     is_correct_string = 'Yes' if output == correct_output else 'No'
  20.     outputs.append([test_input[0], test_input[1], linear_combination, output, is_correct_string])
  21.  
  22. # Print output
  23. num_wrong = len([output[4] for output in outputs if output[4] == 'No'])
  24. output_frame = pd.DataFrame(outputs, columns=['Input 1', '  Input 2', '  Linear Combination', '  Activation Output', '  Is Correct'])
  25. if not num_wrong:
  26.     print('Nice!  You got it all correct.\n')
  27. else:
  28.     print('You got {} wrong.  Keep trying!\n'.format(num_wrong))
  29. print(output_frame.to_string(index=False))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement