explain these python codes with comments , explain briefly >>> for iteration_num in range(5): ... correct_answers = 0 ... for idx, sample in enumerate(sample_data): ... input_vector = np.array(sample) ... weights = np.array(weights) ... activation_level = np.dot(input_vector, weights) +\ ... (bias_weight * 1) ... if activation_level > activation_threshold: ... perceptron_output = 1 ... else: ... perceptron_output = 0 ... if perceptron_output == expected_results[idx]: ... correct_answers += 1 ... new_weights = [] ... for i, x in enumerate(sample): ... new_weights.append(weights[i] + (expected_results[idx] -\ ... perceptron_output) * x) ... bias_weight = bias_weight + ((expected_results[idx] -\ ... perceptron_output) * 1) ... weights = np.array(new_weights) ... print('{} correct answers out of 4, for iteration {}'\ ... .format(correct_answers, iteration_num)) 3 correct answers out of 4, for iteration 0 2 correct answers out of 4, for iteration 1 3 correct answers out of 4, for iteration 2 4 correct answers out of 4, for iteration 3 4 correct answers out of 4, for iteration 4
explain these python codes with comments , explain briefly
>>> for iteration_num in range(5):
... correct_answers = 0
... for idx, sample in enumerate(sample_data):
... input_vector = np.array(sample)
... weights = np.array(weights)
... activation_level = np.dot(input_vector, weights) +\
... (bias_weight * 1)
... if activation_level > activation_threshold:
... perceptron_output = 1
... else:
... perceptron_output = 0
... if perceptron_output == expected_results[idx]:
... correct_answers += 1
... new_weights = []
... for i, x in enumerate(sample):
... new_weights.append(weights[i] + (expected_results[idx] -\
... perceptron_output) * x)
... bias_weight = bias_weight + ((expected_results[idx] -\
... perceptron_output) * 1)
... weights = np.array(new_weights)
... print('{} correct answers out of 4, for iteration {}'\
... .format(correct_answers, iteration_num))
3 correct answers out of 4, for iteration 0
2 correct answers out of 4, for iteration 1
3 correct answers out of 4, for iteration 2
4 correct answers out of 4, for iteration 3
4 correct answers out of 4, for iteration 4
Step by step
Solved in 2 steps