0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Google Colabを学びたい Step7 クラスター分析を実施する

Posted at

はじめに

Google Colabを学びたいのStep7です。クラスター分析を学んでいきます!!

成果物

お寿司のすきな傾向を表示するためのクラスター分析
image.png

ソースコード

# ライブラリのインポート
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage

# 寿司ネタのラベル
labels = ['Salmon', 'Tuna', 'Fatty Tuna', 'Eel', 'Shrimp', 'Octopus',
          'Egg', 'Cucumber Roll', 'Squid', 'Mackerel', 'Horse Mackerel', 'Sea Urchin']

# 寿司ネタごとの特徴量(適当な仮データ)
# 特徴例:脂っこさ, 甘さ, 柔らかさ(0〜10のスケール)
data = np.array([
    [8, 4, 7],   # Salmon
    [7, 3, 8],   # Tuna
    [9, 5, 9],   # Fatty Tuna
    [6, 6, 6],   # Eel
    [4, 7, 5],   # Shrimp
    [3, 2, 6],   # Octopus
    [2, 8, 3],   # Egg
    [1, 3, 2],   # Cucumber Roll
    [3, 4, 4],   # Squid
    [6, 2, 5],   # Mackerel
    [5, 3, 4],   # Horse Mackerel
    [7, 9, 6],   # Sea Urchin
])

# 階層クラスタリング(Ward法)
linked = linkage(data, method='ward')

# デンドログラムを描画
plt.figure(figsize=(12, 6))
dendrogram(linked,
           labels=labels,
           orientation='top',
           distance_sort='descending',
           show_leaf_counts=True)

plt.title("Sushi Ingredient Hierarchical Clustering")
plt.xlabel("Sushi Types")
plt.ylabel("Distance")
plt.grid(True)
plt.show()
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?