Weka 简明教程

Weka - Clustering

群集算法将在整个数据集内找到一组相似实例。WEKA 支持多种群集算法,例如 EM、FilteredClusterer、HierarchicalClusterer、SimpleKMeans 等。你应当完全理解这些算法,以便充分利用 WEKA 的功能。

如同在分类的情况下,通过 WEKA 能够以图形方式可视化检测到的群集。为了演示群集,我们将使用提供的 iris 数据库。数据集包含三类,每类有 50 个实例。每类表示一种类型的 iris 植物。

Loading Data

在 WEKA 浏览器中,选择 Preprocess 选项卡。点击 Open file …​ 选项并在文件选择对话框中选择 iris.arff 文件。当你加载数据时,屏幕看起来如下图所示 −

screen looks

你可以观察到有 150 个实例和 5 个属性。属性的名称列为 sepallengthsepalwidthpetallengthpetalwidthclass 。前四个属性为数字类型,而类为具有 3 个不同值的公称类型。检查每个属性以了解数据库的特性。我们不会针对此数据进行任何预处理,直接进入模型构建。

Clustering

点击 Cluster 选项卡,将群集算法应用到我们加载的数据。点击 Choose 按钮。你会看到下面的屏幕 −

cluster tab

现在,选择 EM 作为群集算法。在 Cluster mode 子窗口中,选择 Classes to clusters evaluation 选项,如下图所示 −

clustering algorithm

点击 Start 按钮处理数据。片刻之后,结果将显示在屏幕上。

接下来,让我们研究一下结果。

Examining Output

数据处理的输出如下图所示 −

examining  output

从输出屏幕中,你可以观察到 −

  1. 在数据库中检测到了 5 个群集实例。

  2. Cluster 0 表示 setosa, Cluster 1 表示 virginica, Cluster 2 表示 versicolor,而后两个群集没有任何与其关联的类。

如果你向上滚动输出窗口,你还可以看到一些统计信息,为各个检测到的群集中各个属性的平均值和标准差。这在下图的屏幕截图中显示 −

detected clusters

接下来,我们将查看群集的视觉表示。

Visualizing Clusters

为了可视化群集,右键点击 EM 中的 Result list 的结果。你会看到以下选项 −

clusters result list

选择 Visualize cluster assignments 。你会看到以下输出 −

cluster assignments

如同在分类的情况下,你会注意到正确和错误识别实例之间的区别。你可以通过改变 X 轴和 Y 轴来分析结果。你可以使用抖动,如同在分类的情况一样,来确定正确识别实例的浓度。可视化图的运算类似于你在分类的情况下所学习的运算。

Applying Hierarchical Clusterer

To demonstrate the power of WEKA, let us now look into an application of another clustering algorithm. In the WEKA explorer, select the HierarchicalClusterer as your ML algorithm as shown in the screenshot shown below −

hierarchical clusterer

Choose the Cluster mode selection to Classes to cluster evaluation, and click on the Start button. You will see the following output −

cluster evaluation

Notice that in the Result list, there are two results listed: the first one is the EM result and the second one is the current Hierarchical. Likewise, you can apply multiple ML algorithms to the same dataset and quickly compare their results.

If you examine the tree produced by this algorithm, you will see the following output −

examine algorithm

In the next chapter, you will study the Associate type of ML algorithms.