Machine Learning

profileSiper
Assignment.pdf

Assignment 5: Multi-Classification

Due date: Mar 13th, 2020 (Friday)

Total Points: 100

Please put your name, student ID, date and time here

Name:

Student ID:

Date:

Time:

In this assignment, you will investigate the handwritten digits dataset.

Sample images:

Please apply the folowing eight methods to classify the handwritten digits dataset.

Split the dataset into training sets and test sets

Fit the training data sets to the following eight algorithms

Print the classification report on the test data sets

Method 1: KNN

Method 2: Linear SVM

Method 3: Gaussian Kernel SVM

Method 4: Naive Bayes

Method 5: Decision Tree

Method 6: Random Forest

Method 7: Voting Classifier

Method 8: Bagging

Assignment 5 file:///C:/Users/Al-Ja/Downloads/Assignment 5.html

1 of 5 3/11/2020, 6:57 PM

In [4]: # Importing the dataset from sklearn.datasets import load_digits digits = load_digits() print(digits)

Assignment 5 file:///C:/Users/Al-Ja/Downloads/Assignment 5.html

2 of 5 3/11/2020, 6:57 PM

{'data': array([[ 0., 0., 5., ..., 0., 0., 0.], [ 0., 0., 0., ..., 10., 0., 0.], [ 0., 0., 0., ..., 16., 9., 0.], ..., [ 0., 0., 1., ..., 6., 0., 0.], [ 0., 0., 2., ..., 12., 0., 0.], [ 0., 0., 10., ..., 12., 1., 0.]]), 'target': array([0, 1, 2, ..., 8, 9, 8]), 'target_names': array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), 'images': array ([[[ 0., 0., 5., ..., 1., 0., 0.], [ 0., 0., 13., ..., 15., 5., 0.], [ 0., 3., 15., ..., 11., 8., 0.], ..., [ 0., 4., 11., ..., 12., 7., 0.], [ 0., 2., 14., ..., 12., 0., 0.], [ 0., 0., 6., ..., 0., 0., 0.]],

[[ 0., 0., 0., ..., 5., 0., 0.], [ 0., 0., 0., ..., 9., 0., 0.], [ 0., 0., 3., ..., 6., 0., 0.], ..., [ 0., 0., 1., ..., 6., 0., 0.], [ 0., 0., 1., ..., 6., 0., 0.], [ 0., 0., 0., ..., 10., 0., 0.]],

[[ 0., 0., 0., ..., 12., 0., 0.], [ 0., 0., 3., ..., 14., 0., 0.], [ 0., 0., 8., ..., 16., 0., 0.], ..., [ 0., 9., 16., ..., 0., 0., 0.], [ 0., 3., 13., ..., 11., 5., 0.], [ 0., 0., 0., ..., 16., 9., 0.]],

...,

[[ 0., 0., 1., ..., 1., 0., 0.], [ 0., 0., 13., ..., 2., 1., 0.], [ 0., 0., 16., ..., 16., 5., 0.], ..., [ 0., 0., 16., ..., 15., 0., 0.], [ 0., 0., 15., ..., 16., 0., 0.], [ 0., 0., 2., ..., 6., 0., 0.]],

[[ 0., 0., 2., ..., 0., 0., 0.], [ 0., 0., 14., ..., 15., 1., 0.], [ 0., 4., 16., ..., 16., 7., 0.], ..., [ 0., 0., 0., ..., 16., 2., 0.], [ 0., 0., 4., ..., 16., 2., 0.], [ 0., 0., 5., ..., 12., 0., 0.]],

[[ 0., 0., 10., ..., 1., 0., 0.], [ 0., 2., 16., ..., 1., 0., 0.], [ 0., 0., 15., ..., 15., 0., 0.], ..., [ 0., 4., 16., ..., 16., 6., 0.], [ 0., 8., 16., ..., 16., 8., 0.], [ 0., 1., 8., ..., 12., 1., 0.]]]), 'DESCR': ".. _digits_dataset:\n\ nOptical recognition of handwritten digits dataset\n --------------------------------------------------\n\n**Data Set Characteristic s:**\n\n :Number of Instances: 5620\n :Number of Attributes: 64\n :Attr ibute Information: 8x8 image of integer pixels in the range 0..16.\n :Missing Attribute Values: None\n :Creator: E. Alpaydin (alpaydin '@' boun.edu.tr)\n :Date: July; 1998\n\nThis is a copy of the test set of the UCI ML hand-written d igits datasets\nhttp://archive.ics.uci.edu/ml/datasets/Optical+Recognition+of+Ha

Assignment 5 file:///C:/Users/Al-Ja/Downloads/Assignment 5.html

3 of 5 3/11/2020, 6:57 PM

In [27]: import matplotlib.pyplot as plt digits.images[0].shape list = [10,100,100,45] fig = plt.figure() for i,j in enumerate(list):

plt.subplot(2,2,i+1) plt.imshow(digits.images[j],cmap='gray')

In [2]: X = digits.data y = digits.target

Step 1. Split the dataset into training data and testing data ( 10 points )

In [ ]:

Step 2. Algorithm Analysis ( 80 points )

Method 1. KNN

In [ ]:

Method 2. Linear SVM

In [ ]:

Method 3. Gaussian Kernal SVM

In [ ]:

Method 4. Naive Bayes

Assignment 5 file:///C:/Users/Al-Ja/Downloads/Assignment 5.html

4 of 5 3/11/2020, 6:57 PM

In [ ]:

Method 5. Decision Tree

In [ ]:

Method 6. Random Forest

In [ ]:

Method 7. Voting Classifier

In [ ]:

Method 8. Bagging

In [ ]:

Step 3: Accuracy Results Table ( 8 points )

KNN L_SVM RBF_SVM NB DT RF Voting Bagging

Accuracy

Weighted Precision

Weighted Recall

Step 4: Conclusion ( 2 Points )

In [ ]:

In [ ]:

In [ ]:

In [ ]:

Assignment 5 file:///C:/Users/Al-Ja/Downloads/Assignment 5.html

5 of 5 3/11/2020, 6:57 PM