Orange: k-Means

From OnnoWiki
Jump to navigation Jump to search

Sumber: https://docs.biolab.si//3/visual-programming/widgets/unsupervised/kmeans.html

Mengelompokan item menggunakan algoritma k-Means clustering.

Input

Data: input dataset

Output

Data: dataset with cluster index as a class attribute

Widget ini menerapkan algoritma k-Means clustering ke data dan mengeluarkan dataset baru di mana indeks cluster digunakan sebagai atribut class. Atribut class yang original, jika ada, dipindahkan ke atribut meta. Skor hasil pengelompokan untuk berbagai k juga ditampilkan di widget.

KMeans-stamped.png
  • Select the number of clusters.
    • Fixed: algorithm clusters data in a specified number of clusters.
    • Optimized: widget shows clustering scores for the selected cluster range:
      • Silhouette (contrasts average distance to elements in the same cluster with the average distance to elements in other clusters)
      • Inter-cluster distance (measures distances between clusters,normally between centroids)
      • Distance to centroids (measures distances to the arithmetic means of clusters)
  • Select the initialization method (the way the algorithm begins clustering):
    • k-Means++ (first center is selected randomly, subsequent are chosen from the remaining points with probability proportioned to squared distance from the closest center)
    • Random initialization (clusters are assigned randomly at first and then updated with further iterations) Re-runs (how many times the algorithm is run from random initial positions; the result with the lowest within-cluster sum of squares will be used) and maximal iterations (the maximum number of iterations within each algorithm run) can be set manually.
  • The widget outputs a new dataset with appended cluster information. Select how to append cluster information (as class, feature or meta attribute) and name the column.
  • If Apply Automatically is ticked, the widget will commit changes automatically. Alternatively, click Apply.
  • Produce a report.
  • Check scores of clustering results for various k.

Contoh

Kita akan mengexplorasi Widget k-Means melalui schema / workflow berikut.

K-MeansClustering-Schema.png.jpeg

Pertama, kita memuat dataset Iris, membaginya menjadi tiga cluster dan menampilkannya di Tabel Data, di mana kita bisa mengamati instance mana yang masuk ke cluster mana. Bagian yang menarik adalah Widget Scatter Plot dan Widget Select Rows.

Karena Widget k-Means menambahkan cluster index sebagai atribut class, Widget Scatter Plot akan mewarnai titik-titik sesuai dengan kelompoknya.

KMeans-Scatterplot.png

Apa yang kami benar-benar tertarik adalah seberapa baik cluster yang dilakukan oleh (unsupervised) clustering algorithm cocok dengan class aktual dalam data. Oleh karena itu, kita menggunakan widget Select Rows, di mana kami dapat memilih class-class individual dan menandai titik-titik terkait di Scatter Plot. Kecocokan yang sempurna terjadi pada setosa, dan cukup bagus untuk dua class lainnya.

K-MeansClustering-Example.png

You may have noticed that we left the Remove unused values/attributes and Remove unused classes in Select Rows unchecked. This is important: if the widget modifies the attributes, it outputs a list of modified instances and the scatter plot cannot compare them to the original data.

Perhaps a simpler way to test the match between clusters and the original classes is to use the Distributions widget.

K-MeansClustering-Example2.png

The only (minor) problem here is that this widget only visualizes normal (and not meta) attributes. We solve this by using Select Columns: we reinstate the original class Iris as the class and put the cluster index among the attributes.

The match is perfect for setosa: all instances of setosa are in the third cluster (blue). 48 versicolors are in the second cluster (red), while two ended up in the first. For virginicae, 36 are in the first cluster and 14 in the second.

Referensi

Pranala Menarik