Cluster visualisieren

Cluster Analysis in Python

Shaumik Daityari

Business Analyst

Warum Cluster visualisieren?

  • Verstehe die gebildeten Cluster
  • Zusätzlicher Schritt zur Validierung der Cluster
  • Trends in Daten erkennen
Cluster Analysis in Python

Einführung in seaborn

  • seaborn: eine Python-Visualisierungsbibliothek auf Basis von matplotlib
  • Bessere, leicht anpassbare Ästhetik als matplotlib
  • Funktionen, die Visualisierungen für Data Analytics vereinfachen
  • Einsatz bei Clustering: hue-Parameter für Plots
Cluster Analysis in Python

Cluster mit matplotlib visualisieren

from matplotlib import pyplot as plt
df = pd.DataFrame({'x': [2, 3, 5, 6, 2],
                   'y': [1, 1, 5, 5, 2],
                   'labels': ['A', 'A', 'B', 'B', 'A']})

colors = {'A':'red', 'B':'blue'}
df.plot.scatter(x='x', y='y', c=df['labels'].apply(lambda x: colors[x])) plt.show()
Cluster Analysis in Python

Cluster mit seaborn visualisieren

from matplotlib import pyplot as plt
import seaborn as sns
df = pd.DataFrame({'x': [2, 3, 5, 6, 2],
                   'y': [1, 1, 5, 5, 2],
                   'labels': ['A', 'A', 'B', 'B', 'A']})

sns.scatterplot(x='x', y='y', hue='labels', data=df) plt.show()
Cluster Analysis in Python

Vergleich beider Visualisierungsmethoden

matplotlib-Plot

seaborn-Plot

Cluster Analysis in Python

Als Nächstes: ein paar Visualisierungen

Cluster Analysis in Python

Preparing Video For Download...