Wednesday, January 6, 2016

KMeans with R studio

Some of you may already know Kmeans ...

What it Kmeans?

The answer is here
http://pengolahancitra.com/index.php?option=com_content&task=view&id=36&Itemid=26
Please later you read for yourself ..

because this directly to the source code wrote:



1.) Open R Studio


2.) Type Source code below:
> require (MASS)
> X <- mvrnorm (n=100, mu=c(5,5),Sigma=matrix(c(1/2,0,0,1/2),nrow=2,ncol=2))
> Y <- mvrnorm (n=100, mu=c(7.5,8),Sigma=matrix(c(1/2,0,0,1/2),nrow=2,ncol=2))
> Z <- mvrnorm (n=100, mu=c(8,5),Sigma=matrix(c(1/2,0,0,1/2),nrow=2,ncol=2))
> data <- rbind (X,Y,Z)
> plot(data)


> kmeans.res <- kmeans (data,centers=3)
> plot(data, col=kmeans.res$cluster)
> points(kmeans.res$centers, cex=2, col=11, pch=19)
> points (matrix (colMeans(data),nrow=1, ncol=2), cex=3, col=12, pch=19)
> kmeans.res$totss
> kmeans.res$betweenss
> kmeans.res$withinss
> kmeans.res$tot.withinss

And the results of the program like this:

Good luck !!!
For the R programming language when calling a function and press enter
misalnya > require (MASS) enter
> X <- mvrnorm (n=100, mu=c(5,5),Sigma=matrix(c(1/2,0,0,1/2),nrow=2,ncol=2))
enter
and so on
such as calling in matlab command window also use the enter
<> It is simple for those of you who want to develop please !!!!!
Ganbattee !!!!!!!



.


No comments:

Post a Comment