Ive written a function which does kmeans clustering on normal distributions. The function can be used on both one dimensional and two dimensional normal distributions. Plotting the 1d kmeans clustering is easy and can be done b using the following:
plot(data[idx==0,0],data[idx==0,1],'ob',
data[idx==1,0],data[idx==1,1],'or',
data[idx==2,0],data[idx==2,1],'og',
data[idx==3,0],data[idx==3,1],'oy',
data[idx==4,0],data[idx==4,1],'oc')
plot(centroids[:,0],centroids[:,1],'sg',markersize=8)
show()
which will give a plot like this:
a plot of a 2d normal distribution looks like:
A 2-D normal distribution has mean = [a b]
and var = [[p q],[r s]]
The centroids obtained for clustering of 2d distributions also have the same shape as the mean and var of the points (obviously). The problem I'm facing is with plotting of this data. How can this be visualized using python and matplotlib. So the points in 1-d case will be replaced by ellipses and the centroid will also be an ellipse. The clustering should look something like:
where black ellipses are the 2d distributions and red ones are detected 2d centroids.
The plot function that im using to plot a single 2d distribution is:
def plot2DND(mean, variance):
mean1 = mean.flatten()
cov1 = variance
nobs = 2500
rvs1 = np.random.multivariate_normal(mean1, cov1, size=nobs)
plt.plot(rvs1[:, 0], rvs1[:, 1], '.')
plt.axis('equal')
plt.show()
The following figure gives a better visualization of the requirement(From: http://www.lix.polytechnique.fr/~nielsen/pdf/2008-C-ClusteringNormal-ETVC.pdf)
Is it possible to achieve something like this using python and matplotlib(or other libs). Or is a better visualization possible for this type of data?