Production Level Knowledge & Tips

  1. 未分類
  2. 10 view

[R]Try to make clusters with k-means

What I want to do

I’ll use R which is for analyzing to make clusters with the data set.

Preparing

I’ll install R for ubuntu13.04.
We can use apt-get to do it.
$ sudo apt-get install r-base
$ sudo apt-get install r-cran-*
$ R

R version 2.14.1 (2011-12-22)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

>

Apply k-means to iris data set

It’s easy to apply k-means for iris data set with R.
clusters <- kmeans(iris[1:4], 2)
jpeg("test.jpg", width=640, height=480, pointsize=12, bg="white")
plot(iris[1:4], col=clusters$cluster)
points(clusters$centers, col=1:2, pch=8)
$R --vanilla < kmeans-sample.R
test
The result is following.

未分類 recent post

  1. Install sbt 1.0.0 and run sample template

  2. Visualization of Neural Network and its Train…

  3. [Machine Learning]Created docker image includ…

  4. [Node.js]How to write batch script with Node.…

  5. [Hive]Get top n items for each category

関連記事

PAGE TOP