Question: The data arrays (x, y) currently in the memory are organized so that all data points with a given label (e.g. 'Setosa') lie in


The data arrays (x, y) currently in the memory are organized so that all data points with a given label (e.g. 'Setosa') lie in a contiguous part of the arrays (X, y). In this question we will check the impact of changing the order of the data on the number of iterations required to learn a correct perceptron. The commented code below needs a small change in order to generate a random shuffle (permutation) of the data. Please look up the particular functions of the code, see how they work and then do the required modification and uncomment/evaluate the code. [74] # establish a random shuffle s = np.arange (10) [ ] S # np.random.shuffle(s) # shuffle sample # X_shuffle = X[s]; #y_shuffle = y[s]; array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) Modify the code below as follows: (i) Pick a sufficiently small n so that convergences takes 20 iterations or more. (ii) Add an extra line that fits the perceptron on the shuffled data. (iii) Plot the error for both training processes (the original data and the shuffled data). What do you observe? ppn.fit (x, y) plt.plot(range (1, len(ppn.errors_) +1), ppn.errors, marker='0) plt.xlabel('Epochs') plt.ylabel('Number of updates') # plt.savefig('images/02_07.png', dpi=300) plt.show() Give your answers here. [ ] ppn = Perceptron(eta=0.0001, n_iter=20, random_state=1) ppn.fit (x, y) plt.plot(range (1, len(ppn.errors_) + 1), ppn.errors, marker='o') plt.xlabel('Epochs') plt.ylabel('Number of updates') plt.show()
Step by Step Solution
There are 3 Steps involved in it
To modify the code as instructed you can make the following changes python Establish a random shuffl... View full answer
Get step-by-step solutions from verified subject matter experts
