Datavoorbereiding voor clusteranalyse

Clusteranalyse in Python

Shaumik Daityari

Business Analyst

Waarom data voorbereiden voor clustering?

  • Variabelen hebben onvergelijkbare eenheden (productafmetingen in cm, prijs in $)
  • Variabelen met dezelfde eenheid hebben heel verschillende schalen en varianties (uitgaven aan ontbijtgranen, reizen)
  • Ruwe data kan tot bias in clustering leiden
  • Clusters kunnen sterk afhangen van één variabele
  • Oplossing: normalisatie van afzonderlijke variabelen
Clusteranalyse in Python

Normalisatie van data

Normalisatie: data herschalen zodat de standaardafwijking 1 is

x_new = x / std_dev(x)

from scipy.cluster.vq import whiten
data = [5, 1, 3, 3, 2, 3, 3, 8, 1, 2, 2, 3, 5]
scaled_data = whiten(data)
print(scaled_data)
[2.73, 0.55, 1.64, 1.64, 1.09, 1.64, 1.64, 4.36, 0.55, 1.09, 1.09, 1.64, 2.73]
Clusteranalyse in Python

Illustratie: normalisatie van data

# Import plotting library
from matplotlib import pyplot as plt

# Initialize original, scaled data
plt.plot(data, 
         label="original")
plt.plot(scaled_data, 
         label="scaled")
# Show legend and display plot
plt.legend()
plt.show()

Clusteranalyse in Python

Zo meteen: zelf oefenen

Clusteranalyse in Python

Preparing Video For Download...