Dimensionsreduktion und Clustering — Unsupervised Machine Learning
Quelle: scaler.com
Quelle: scaler.com
Quelle: scaler.com
\[ \text{min} \left( \frac{1}{n} \sum_{i}^{n} \left( x_i^T x_i - (u_1^T x_i)^2 \right) \right) \]
# Daten laden und skalieren
data(iris)
iris_scaled <- scale(iris[, -5])
# PCA durchführen
pca <- prcomp(iris_scaled)
# Zusammenfassung der PCA
summary(pca)
# PCA-Plot
library(ggplot2)
pca_data <- as.data.frame(pca$x)
pca_data$Species <- iris$Species
ggplot(pca_data, aes(x = PC1, y = PC2, color = Species)) +
geom_point() +
labs(title = "PCA der Iris-Daten", x = "Hauptkomponente 1", y = "Hauptkomponente 2")
Quelle: scaler.com
Quelle: scaler.com
# K-Means Clustering durchführen
set.seed(123)
kmeans_result <- kmeans(iris_scaled, centers = 3)
# K-Means Plot
kmeans_data <- as.data.frame(iris_scaled)
kmeans_data$Cluster <- factor(kmeans_result$cluster)
ggplot(kmeans_data, aes(x = PC1, y = PC2, color = Cluster)) +
geom_point() +
labs(title = "K-Means Clustering der Iris-Daten", x = "Hauptkomponente 1", y = "Hauptkomponente 2")
Quelle: scaler.com
Metrik | Optimum | Idee |
---|---|---|
Silhouette | ↑ | Dichte vs. Trennung |
Davies-Bouldin | ↓ | Verhältnis Intra-/Inter-Distanzen |
Calinski-Harabasz | ↑ | Varianz zwischen / innerhalb Cluster |
Dunn-Index | ↑ | Kleinster Inter-Cluster Abstand relativ zu größter Intra-Cluster-Distanz |
Gap Statistic | ↑ | SSE-Lücke zu Referenz (Bootstrapping) |
Praxis-Tipp: Kombination mehrerer Metriken
conclust
, clustConstraint