Clusters visualiseren

Clusteranalyse in Python

Shaumik Daityari

Business Analyst

Waarom clusters visualiseren?

  • Begrijp de gevormde clusters
  • Extra stap in de validatie van clusters
  • Ontdek trends in data
Clusteranalyse in Python

Kennismaking met seaborn

  • seaborn: een Python-datavisbibliotheek op matplotlib
  • Betere, makkelijk aanpasbare vormgeving dan matplotlib
  • Functies die visualisatietaken voor data-analyse eenvoudiger maken
  • Toepassing bij clustering: hue-parameter voor plots
Clusteranalyse in Python

Clusters visualiseren met matplotlib

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()
Clusteranalyse in Python

Clusters visualiseren met seaborn

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()
Clusteranalyse in Python

Vergelijking van beide visualisatiemethoden

matplotlib-plot

seaborn-plot

Clusteranalyse in Python

Nu: probeer wat visualisaties

Clusteranalyse in Python

Preparing Video For Download...