User Tools

Site Tools


cs501r_f2016:lab2

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
cs501r_f2016:lab2 [2016/09/02 04:39]
wingated
cs501r_f2016:lab2 [2021/06/30 23:42] (current)
Line 10: Line 10:
 You should turn in an iPython notebook that implements the perceptron algorithm on two different datasets: the Iris dataset, and the CIFAR-10 dataset. ​ Because the perceptron is a binary classifier, we will preprocess the data and "​squash"​ it to create two classes. You should turn in an iPython notebook that implements the perceptron algorithm on two different datasets: the Iris dataset, and the CIFAR-10 dataset. ​ Because the perceptron is a binary classifier, we will preprocess the data and "​squash"​ it to create two classes.
  
-Your notebook should also generate a visualization that shows classification accuracy at each iteration, along with the log of the l2 norm of the weight vector, for two different values of the perceptron'​s step size.  Examples of both are shown at the right. ​ Since there are two datasets, and there are two visualizations per dataset, your notebook should produce a total of 4 plots.+Your notebook should also generate a visualization that shows classification accuracy at each iteration, along with the log of the l2 norm of the weight vector, for two different values of the perceptron'​s step size.  Examples of both are shown at the right (for the CIFAR-10 dataset).  Since there are two datasets, and there are two visualizations per dataset, your notebook should produce a total of 4 plots.
  
 **Please cleanly label your axes!** **Please cleanly label your axes!**
Line 32: Line 32:
  
   * 70% Correct implementation of perceptron algorithm   * 70% Correct implementation of perceptron algorithm
-  * 20% Tidy and legible visualization of loss function+  * 20% Tidy and legible visualization of weight norm
   * 10% Tidy and legible plot of classification accuracy over time   * 10% Tidy and legible plot of classification accuracy over time
  
Line 93: Line 93:
 In the wikipedia description of the perceptron algorithm, notice the function ''​f''​. ​ That's the Heaviside step function. ​ What does it do? In the wikipedia description of the perceptron algorithm, notice the function ''​f''​. ​ That's the Heaviside step function. ​ What does it do?
  
-You should run the perceptron for at least 100 steps.+You should run the perceptron for at least 100 steps. ​ Note that your perceptron will probably converge in much fewer on the Iris dataset!
  
 You should also test different step sizes. Wikipedia doesn'​t discuss how to do this, but it should be straightforward for you to figure out; the algorithm description in the lecture notes includes the step size.  (But try to figure it out: consider the update equation for a weight, and ask yourself: where should I put a stepsize parameter, to be able to adjust the magnitude of the weight update?​) ​ You should also test different step sizes. Wikipedia doesn'​t discuss how to do this, but it should be straightforward for you to figure out; the algorithm description in the lecture notes includes the step size.  (But try to figure it out: consider the update equation for a weight, and ask yourself: where should I put a stepsize parameter, to be able to adjust the magnitude of the weight update?​) ​
  
-For the Iris dataset, you should test ''​c=1'',​ ''​c=0.1'',​ ''​c=0.01''​.+For the Iris dataset, you should test at least ''​c=1'',​ ''​c=0.1'',​ ''​c=0.01''​.
  
-For the CIFAR-10 dataset, you should test ''​c=0.001'',​ ''​c=0.00001''​.+For the CIFAR-10 dataset, you should test at least ''​c=0.001'',​ ''​c=0.00001''​.
  
  
Line 107: Line 107:
  
 This should only take a single line of code.  Hint: can you rewrite the l2 norm in terms of dot products? This should only take a single line of code.  Hint: can you rewrite the l2 norm in terms of dot products?
 +
 +** Plotting results **
 +
 +You may use any notebook compatible plotting function you like, but I recommend ''​matplotlib''​. ​ This is commonly imported as
 +
 +<code python>
 +import matplotlib.pyplot as plt
 +</​code>​
 +
 +To create a new figure, call ''​plt.figure''​. ​ To plot a line, call ''​plt.plot''​. ​ Note that if you pass a matrix into ''​plt.plot'',​ it will plot multiple lines at once, each with a different color; each column will generate a new line.
 +
 +Note that if you use matplotlib, you may have to call ''​plt.show''​ to actually construct and display the plot.
 +
 +Don't forget to label your axes!
 +
 +You may find [[http://​matplotlib.org/​users/​pyplot_tutorial.html|this tutorial on pyplot]] helpful.
  
 ---- ----
Line 122: Line 138:
  
 plt.figure plt.figure
 +plt.plot
 plt.xlabel plt.xlabel
 plt.ylabel plt.ylabel
cs501r_f2016/lab2.1472791148.txt.gz ยท Last modified: 2021/06/30 23:40 (external edit)