# Python代写 | Computer vision 2021 Assignment 3: image classification

1 Computer vision 2021 Assignment 3: image classification
This assignment contains 3 questions split across 2 notebooks. The first two questions, below,
require you to complete and extend a simple 2D classifier.
2 Question 1: Perceptron training algorithm (30%)
Below is the usual code to import libraries we need. You can modify it as needed.
[ ]: import numpy as np # This is for mathematical operations
# this is used in plotting
import matplotlib.pyplot as plt
import time
import pylab as pl
from IPython import display
%matplotlib inline
from perceptron import *
1. Starting from the boiler plate code provided in perceptron.py, implement the perceptron
training algorithm as seen in the lecture. This perceptron takes a 2D point as input and clas-
sifies it as belonging to either class 0 or 1. By changing the number_of_samples parameter,
different sample sizes can be generated for both classes.
You need the address the section of the code marked with #TODO
[ ]: number_of_samples = 100
max_number_of_epochs = 10
X = np.random.rand(number_of_samples,2)
X = np.append(X, np.ones((X.shape[0],1)),axis = 1)

Y = X[:,1] > (X[:,0])
Y = np.float32(Y)
Y = Y.reshape((number_of_samples,1))
p = Perceptron(3)
p.train(X,Y,max_number_of_epochs)
2. The code plots the ground-truth boundary between the two classes. We know this is the
ground-truth because this is the boundary from which we generated data. However, even
though the estimated line can correctly classify all the training samples, it might not agree
with the ground-truth boundary.
• Explain why this happens.
• What is the potential disadvantage of such a decision boundary?
• How could you change the training algorithm to reduce this disadvantage? (Implementation
not required)
,→this assignment)
3. In some training sessions, you might observe the boundary oscillating between two solutions
and not reaching 100% accuracy. Discuss why this can happen and modify the training
algorithm to correct this behaviour. We will call this the modified algorithm. (Hint: learning
rate)