Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve this using python. Please show the code and explain! Question 4: Changing the data order in training The data arrays (x,y) currently in

Please solve this using python. Please show the code and explain!

image text in transcribed

Question 4: Changing the data order in training The data arrays (x,y) currently in the memory are organized so that the 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 in 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 (also called 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. In [10]: # establish a random shuffle # s = np.arange (10) # np.random.shuffle(s) # shuffle sample # X shuffle = X[S]; # y_shuffle = y(s); In [ ]: Modify the code below as follows: (i) Pick a sufficiently small , 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, and the shuffled ata) What do you observe? In [ ]: N 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 Question 4: Changing the data order in training The data arrays (x,y) currently in the memory are organized so that the 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 in 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 (also called 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. In [10]: # establish a random shuffle # s = np.arange (10) # np.random.shuffle(s) # shuffle sample # X shuffle = X[S]; # y_shuffle = y(s); In [ ]: Modify the code below as follows: (i) Pick a sufficiently small , 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, and the shuffled ata) What do you observe? In [ ]: N 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions