QUICK CLUSTER: Use fixed format for cluster centers.
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 28 Jan 2025 22:22:51 +0000 (14:22 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 28 Jan 2025 22:22:51 +0000 (14:22 -0800)
This command used the variables' own formats for their centers.  This was
a bad idea for at least two reasons.  First, the variables might have a
format that does not show any decimal places, but clusters wouldn't
ordinarily have integer centers, so this is confusing.  Second, if a
cluster center happens to have a value label, it could be shown instead,
which is even more confusing.  This fixes the problem by using a fixed
format instead.

Thanks to Andreas Hammer for reporting the problem.

src/language/commands/quick-cluster.c
tests/language/commands/quick-cluster.at

index 128130afe3f5d0a6864888fd1fe38d652883a2bf..cb5817006995298844418d41cd9607125d8a1b87 100644 (file)
@@ -549,9 +549,7 @@ quick_cluster_show_centers (struct Kmeans *kmeans, bool initial, const struct qc
     for (size_t j = 0; j < qc->n_vars; j++)
       {
         double x = gsl_matrix_get (matrix, kmeans->group_order->data[i], j);
-        union value v = { .f = x };
-        pivot_table_put2 (table, i, j,
-                          pivot_value_new_var_value (qc->vars[j], &v));
+        pivot_table_put2 (table, i, j, pivot_value_new_number (x));
       }
 
   pivot_table_submit (table);
index 12f4b2ac43b6dc0a6689e38580a4066f8156c5f2..f467d1d6b2f4a50ee7d36561f79129dfb51dfc63 100644 (file)
@@ -350,14 +350,14 @@ AT_CHECK([pspp -O format=csv quick-cluster.sps], [0], [dnl
 Table: Initial Cluster Centers
 ,Cluster,,
 ,1,2,3
-x,-11,-12,11
-y,-12,11,11
+x,-10.80,-11.65,11.10
+y,-11.76,10.81,10.91
 
 Table: Final Cluster Centers
 ,Cluster,,
 ,1,2,3
-x,-10,-10,10
-y,-10,10,10
+x,-10.22,-10.14,10.28
+y,-10.01,10.22,9.89
 
 Table: Number of Cases in each Cluster
 ,,Count