08-problems.pdf
(
65 KB
)
Pobierz
Artificial Neural Networks
Prof. Dr. Sen Cheng
Nov 22, 2021
Problem Set 8: Perceptron
Tutors:
Nicolas Diekmann (nicolas.diekmann@rub.de), Sandhiya Vijayabaskaran (sandhiya.vijayabaskaran@rub.de)
1. Load the Iris dataset from
sklearn.datasets
(at sci-kit learn’s website you can find an example for how to load
and display the data). The dataset contains measures of the flowers of three species of Iris (Iris setosa, Iris
virginica and Iris versicolor). Four features were measured for each sample: the length and the width of the
sepals and petals in centimeters. Extract the first two features (sepal length and width) and make a scatter
plot from them. Use two different colors to distinguish Iris setosa samples from the rest. Is the data linearly
separable?
2. Implement the perceptron algorithm from scratch. You can follow the pseudocode suggested below and a
skeleton class you can base your code on is provided in
Problem Perceptron.py.
Note that, unlike on the
version described in the lecture notes, we are recalculating the overall classification error after every weight
update. This is somewhat inefficient, but for the sake of this tutorial, it is interesting to see the evolution of the
error at a finer scale. Then, use your perceptron to classify Iris setosa based on sepal length and width. Plot the
resulting decision boundary together with the data points.
Algorithm 0.1
Perceptron Algorithm - Tutorial variant
Require:
X, Y
1:
initialize
w
=
0 or small random values
2:
errors = count total number of misclassified items in training set
3:
for
epoch = 0
to
maximum allowed epochs
do
4:
shuffle X, Y
5:
for all
data pairs
i
do
6:
if
y
i
y
i
=
−1
then
ˆ
7:
update weights using the rule:
w
←
w
+
2ηy
i
x
i
8:
errors = count total number of misclassified items in training set
9:
end if
10:
if
errors
≤
maximum allowed errors
then
11:
return
solution found!
12:
end if
13:
end for
14:
end for
3. Plot the training error after each iteration of the algorithm. Think about what could happen if your design
employed a limited number of iterations.
4. Explore the effect of the learning rate on the speed of convergence when you start with
w
=
0. Draw a conclu-
sion.
5. Extract the first and fourth features (sepal length and petal width) and make a scatter plot showing Iris virginica
vs the rest. What would happen if a perceptron tried to classify Iris virginica?
1
6. Iris virginica can be best classified by the ’Pocket Perceptron’. The pocket perceptron keeps in ’it’s pocket’
the weights encountered during training which led to the lowest classification error. After training, the weights
in the pocket are returned instead of the last ones. Implement the pocket algorithm and use it to classify Iris
virginica. For each iteration, plot the training error as well as the error associated with the best solution seen so
far. In what way is this modification of the Perceptron’s basic algorithm helpful?
2
Plik z chomika:
mxp-pl
Inne pliki z tego folderu:
08-Perceptron.pdf
(161 KB)
lec08-quiz.pdf
(116 KB)
08-problems.pdf
(65 KB)
Problem_Perceptron.py
(2 KB)
Inne foldery tego chomika:
0 - Introduction to scientific computing
01-02 - Introduction-Optimization
03-Regression
04-Classification
05-Model Selection
Zgłoś jeśli
naruszono regulamin