Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีให้ sns.clustermap ใช้เมทริกซ์ระยะทางที่คำนวณแล้วใน Matplotlib


ใช้ clustermap กับข้อมูลที่มีเมทริกซ์ระยะทางสำเร็จรูป

โหลดชุดข้อมูลตัวอย่าง แล้ววาด hierarchically-clustered heatmap

ขั้นตอน

  1. ตั้งค่า theme หลายพารามิเตอร์พร้อมกัน
  2. โหลดข้อมูลตัวอย่างจากออนไลน์
  3. แยกคอลัมน์ species ด้วย pop()
  4. วาด heatmap แบบ hierarchical clustering ด้วย clustermap()
  5. แสดงด้วย show()

ตัวอย่างโค้ด

from matplotlib import pyplot as plt
import seaborn as sns

plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True

sns.set_theme(color_codes=True)
iris = sns.load_dataset("iris")
species = iris.pop("species")
g = sns.clustermap(iris)
plt.show()

ผลลัพธ์

วิธีให้ sns.clustermap ใช้เมทริกซ์ระยะทางที่คำนวณแล้วใน Matplotlib