Engineering - Electrical Engineering EEN330: Random Signals & Noise Lab Assignment 2 K-means Algorithm

abcinfo
lab2.pdf

EEN330: Random Signals & Noise

Lab Assignment 2

K-means Algorithm

Dr. Mohammed Ghazal Prepared by: Eng. Rima Masri

Delivered by: Eng. Samr Samir Ali

May 03, 2016

This lab assignment aims to consolidate the students concepts about the usage of Expectation Maximization technique and K-means Algorithm.

Instructions:

• Follow the given instructions and hints while solving your experiment.

• Use the help xyz command to get more information on command xyz().

• Answer the questions given in the lab manual and provide the Matlab codes and snapshots of the outputs.

Lab Experiment (i) Clustering With K-mean Algorithm

In the first part of our lab, we are going to make some fake data with two groups and plot these data. After that, we are going to cluster the data using k-means algorithm and plot the results.

(a) Before we start, read about k-means algorithms and understand its concept.

(b) Define the concept of k-means clustering and illustrate how does it work.

(c) Open Matlab and create a new script.

(d) Assign the sample size to be 150. Then create a matrix of random numbers using randn() comand similar to randn(x,y)+3 to assure that the random values are positive. Assign the matrix of random numbers to group ’x’ . [Note: the size of the group is (2*sample size x 1)].

1

CEN320 2/??

(e) Repeat the step in (d) with assigning the result to group ’y’.

(f) Using the subplot() command, divide the current figure into 1 by 2 grid and create an axes in the first position of the grid.

(g) Plot ’y’ with respect to ’x’in black circles and set the fill color for marker to be black.

(h) Combine ’x’ and ’y’ in a matrix called data2 where the values of ’x’ represent coloumn 1 and the values of ’y’ represent coloumn 2.

(i) Cluster ’data2’ to 2 clusters using kmeans() command and save the resluts in ’IDX’

(j) Plot ’x’ and ’y’ based on ’IDX’. The points are filled with size 50. [Hint: use the command scatter()].

CEN320 3/??

(k) Save and run the script. What do you observe?

(l) Write down the advantages and disadvantages of k-means algorithm.