Assignment 6: Perceptron Learning and Classification

CSE 415: Introduction to Artificial Intelligence
The University of Washington, Seattle, Winter 2023
Due: Monday, Nov. 27, via GradeScope at 11:59 PM.

Iris setosa

Introduction

The perceptron is a basic computational model for a neuron or simple neural network that served as a starting point for the development of techniques such as deep learning. By studying the perceptron, we can gain familiarity with many of the basic concepts of neural networks and ML as well as better understand how such techniques complement those of state-space approaches in AI.


The basic perceptron model is described in the associated reading for this assignment.

This assignment is about how perceptrons are trained, and it involves training and testing to perform classification of data into categories.

We will be primarily using a dataset is derived from the classical Fisher Iris dataset, however we will also be using other datasets.
We'll consider a 2-class classification problem, and you'll implement a very basic binary classifier and the standard perceptron learning algorithm. As part of the assignment, you'll submit a report with your answers to questions based on the code you implement, as well as what happens when you run the code.

Binary Classification

Begin by downloading the A6 starter files.
A6-Report.docx
plot_test.py
binary_perceptron.py
plot_bp.py
remapper.py
run_2_class_2_feature_iris_data.py
iris-lengths-only-2-class-training.csv
iris-lengths-only-2-class-testing.csv
ring-data.csv
Next, run the plot_test.py, and then install the matplotlib module if you don't have it already. You can typically install it by typing the following on a command line:
pip3 install matplotlib
However, depending on how your Python is already set up, that might not work and you can try substituting "pip" for the "pip3". However, on some systems, "pip" will only install it for Python 2.7. If you have trouble installing matplotlib, the staff will try to facilitate your setup through posts on ED or in office hours.

The file A6-Report.docx is a template for your report. It contains ten questions that you should answer.

Binary Perceptron

The binary_perceptron.py file is where you will implement your main binary classifier and your training algorithm. The other files will import and run your binary_perceptron code. Implement the indicated methods in binary_perceptron.py and use them to answer some of the questions in the report file.

Plotting Data

Apart from the file binary_perceptron.py, there is also a file plot_bp.py that implements a class PlotBinaryPerceptron. This class can be used to plot the binary perceptron given any dataset with 2 features and labels +1 (positive) and -1 (negative).
The PlotBinaryPerceptron class already has a placeholder dataset, however, in order to provide the dataset of your choice to train the perceptron, you need to extend the class.
The file run_2_class_2_feature_iris_data.py provides an example of how to do so. In this case, it makes use of the Fischer Iris dataset with 2 features and 2 classes, and contains both a train and a test set.
Similar to this, you'll need to run a binary perceptron on another dataset ring-data.csv (Note: This class doesn't have a separate train and test datasets, so you won't need to test for errors).

In order to do so, make a file called run_ring_data.py, and implement a class PlotRingBP that can plot a binary perceptron using the ring-data.csv. It must also possess an instance variable IS_REMAPPED. When the variable is False, the class must plot the dataset as it is, and when True, it plots a remapped version of the dataset (using the function provided in remap.py).

Turn-In Instructions

Turn-ins for A6 at Gradescope are :

A6-Report.pdf (the report file as a .pdf)
binary_perceptron.py
run_ring_data.py
Note that your files file should not import any additional modules apart from the standard Python library.

Autograder

Some portions of the code you submit (mainly the perceptron) will be graded by an autograder. Please ensure that all the code you write is present in the specified format so that the autograder can evaluate your code correctly. As for the remaining code, you will have a bit more leeway to design your scripts as long as they meet the requirements in the spec. Note that some tests may depend on the prior tests to be correct if there are dependencies between the functions.

Also, please note that the autograder tests will not have any outputs as the autograder is built in a way that it cannot securely reveal exactly what a student's error is. So you will need to develop your own tests to figure out what the problem is. However, from the names of the tests, you should be able to easily identify the problematic method.

The code may be evaluated for neatness and formatting, and having a clear code will be helpful if partial credit is to be provided.

Updates and Corrections

If needed, updates and corrections will be posted here, and/or in ED.