LoginSignup
4
3

More than 5 years have passed since last update.

TDAにIrisデータを適用しただけのチュートリアル

Last updated at Posted at 2018-09-12

はじめに

PCAでIrisのデータを4次元から2次元に次元圧縮を行い,その座標から単体複体を作成します.
そしてその単体複体からPD図とバーコードの図を作ってみるチュートリアルになります.
手弁当ですが,こちらを参考にしました.
https://qiita.com/NoriakiOshita/items/005bb17793f15bcb48b8

tda.py
import dionysus as d
import numpy as np
import matplotlib.pyplot as plt

from sklearn import datasets
iris = datasets.load_iris()
# 4次元のデータ
features = iris.data

from sklearn.decomposition import PCA
pca = PCA(n_components=2)
pca.fit(features)
pca_point = pca.transform(features)

plt.scatter(pca_point[iris.target==0,0], pca_point[iris.target==0,1])
plt.scatter(pca_point[iris.target==1,0], pca_point[iris.target==1,1])
plt.scatter(pca_point[iris.target==2,0], pca_point[iris.target==2,1])

スクリーンショット 2018-09-13 0.53.43.png

tda.py
# 単体複体を作る
f = d.fill_rips(pca_point, 2, 1.)
p = d.homology_persistence(f)
dgms = d.init_diagrams(p, f)

# PD図をプロットします.matplotlibはライブラリの内部で宣言しているので
d.plot.plot_diagram(dgms[1], show = True)

# バーコード図をプロット
d.plot.plot_bars(dgms[1], show = True)

スクリーンショット 2018-09-13 0.55.24.png

スクリーンショット 2018-09-13 0.55.32.png

おわりに

これが何に応用できるかは分かりませんが,たったの4次元での例になってしまいましたがより高次元の特徴を捉えたいときにはこのTDAという手法は役に立つそうです.

宣伝

札幌で人工知能の数理に関する勉強会を開催します.
参加者と発表者を現在募集中です.
https://ai-math.connpass.com/event/100323/

また札幌でアルバイトとして雇ってくれる会社も募集しています.
雇ってくれる方がいましたら以下にメールください.
oshitanoriaki@gmail.com

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3