Tech Tips

  1. 機械学習・AI
  2. 1019 view

[R]k-meansでirisをクラスタリングしてみる

やりたいこと

Rという統計処理用の言語を使ってデータを適当にグループ分けしてみる。

準備

Rをubuntu13.04にインストールする。
これはapt-getでOK。
$ 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.

>

k-meansをirisデータセットに適用する

Rだとk-meansを実装する必要がないから簡単。
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
実行結果はこんな感じになる。

機械学習・AIの最近記事

  1. LangChain Agents を使用して自動的に機械学習モデルのパラメータをチューニン…

  2. TF-Agents で独自の環境を利用する方法

  3. Tensorboardを使ってニューラルネットワークと学習の状況を可視化する

  4. [機械学習]各種Pythonライブラリ入りの実験用Dockerイメージを作った

  5. [機械学習]機械学習の種類

関連記事

PAGE TOP