Starting from:

$30

EE59-Homework 1 Nearest-means Classifier Using Euclidean Distance Solved

In this problem you will code a nearest-means classifier, using Euclidean distance (L2 norm).  You will then use the classifier on data we provide.  

 Note that you are to write the code for the classifier and error-rate computation yourself;  using a toolbox’s or library’s function or module that implements this (or similar) classifier is not sufficient.  If you use python, this means that you can use built-in functions, numpy, and matplotlib.  Use of other libraries or packages (e.g., pandas or scikit-learn) are not in the spirit of this homework problem and will result in points deducted.  

 Your code should take as input a set of data points (training dataset) that are labeled according to class, and should calculate a representation of the classifier (class means and a way to use them to classify data points).  Once the classifier is “trained” (class means are calculated), your code should be able to calculate the error rate obtained when classifying training data, and calculate the error rate obtained when classifying test data.  Error rate is defined as the number of misclassified data points divided by the total number of data points classified, usually expressed as percentage.  In addition, with the aid of a supplied plotting function, you will plot the training data points, resulting class means, decision boundaries, and decision regions.   

 You will use your implemented nearest-means classifier on 3 different datasets: two synthetic datasets, and one real dataset (“wine” from UCI machine learning repository).   

 To help you, the following files are available for download on the course web site, in “Week 2”, along with this HW assignment:

            (i)     Dataset files (containing labeled data points).  

                     MATLAB:  synthetic1.mat, synthetic2.mat, wine.mat.  

                For each dataset file, there are in total 4 variables: 'feature_train', 'label_train',

'feature_test' and 'label_test'. While feature_xxx stores the data points (inputs xn, n=1,2,!,N ) for training (or testing, respectively), label_xxx are the class labels for these data points ( yn, n=1,2,!,N ). Each row in feature_xxx corresponds to a data point, and each column corresponds to a feature. Class labels are stored as a column vector in label_xxx, where the ith entry corresponds to the ith data point in the feature_xxx file.  

                     Python: 

 sythetic1_train.csv, synthetic1_test.csv, sythetic2_train.csv, synthetic2_test.csv,  wine_train.csv,  wine_test.csv.  

 Each csv file has one row for each data point, and one column for each feature; except the last column contains the class labels (each label is an integer from 1 to C, in which C is the number of classes).  

    

(ii) PlotDecBoundaries.m or PlotDecBoundaries.py function helps you plot the decision boundary and regions.  

 To use PlotDecBoundaries.m (or PlotDecBoundaries.py), you only need to pass in 3 variables, which are training data points of all classes, class labels of all training data points, and sample means for all classes.  

 For training data points, you need to be consistent with the format of feature_train (or any of the csv files), where a row corresponds to a data point; it should contain no class labels.  The class labels variable should also follow the format of label_train (or in python, one column of class labels, same order as rows of “training”).  For sample mean, the ith row needs to be set as the sample mean of  ith  class.

 Please answer the following parts.  Note that the data is unnormalized; please keep it unnormalized throughout your work on this problem (that is, do not normalize the data yourself in this problem).  

(a)        For each of the two synthetic datasets, there are in total C=2 classes and D=2 features. For each synthetic dataset:  (i) train the classifier, plot the (training-set) data points, the resulting class means, decision boundaries, and decision regions (using PlotDecBoundaries()); also run the trained classifier to classify the data points from their inputs; give the classification error rate on the training set, and separately give the classification error rate on the test set.  The test-set data points should never be used for training.  Turn in the plots and error rates.  

Hint:  You might want to check your code first, by trying it out with just two or three training data points in each class, for which you can check the results.  

(b)        Is there much difference in error rate between the two synthetic datasets?  Why or why not?  

 Parts (c)-(e) below use the “wine” dataset, which is for classifying the cultivar of the grape plant a wine was made from, given measured attributes of the wine.  This dataset is briefly described at (in which “attribute” means “feature”): 

More products