Spaces:
Running
Running
ping98k
commited on
Commit
·
34e0278
1
Parent(s):
0e793c9
Reduce K-Means iteration count from 200 to 100; adjust UMAP neighbor calculation for improved clustering performance
Browse files
main.js
CHANGED
@@ -73,7 +73,7 @@ document.getElementById("kmeans-btn").onclick = async () => {
|
|
73 |
const n = embeddings.length, dim = embeddings[0].length;
|
74 |
let centroids = Array.from({ length: k }, () => embeddings[Math.floor(Math.random() * n)].slice());
|
75 |
let labels = new Array(n).fill(0);
|
76 |
-
for (let iter = 0; iter <
|
77 |
for (let i = 0; i < n; ++i) {
|
78 |
let best = 0, bestDist = Infinity;
|
79 |
for (let c = 0; c < k; ++c) {
|
@@ -92,7 +92,8 @@ document.getElementById("kmeans-btn").onclick = async () => {
|
|
92 |
for (let c = 0; c < k; ++c) if (counts[c]) for (let d = 0; d < dim; ++d) centroids[c][d] /= counts[c];
|
93 |
}
|
94 |
// UMAP for 2D projection
|
95 |
-
const
|
|
|
96 |
const proj = umap.fit(embeddings);
|
97 |
// Group lines by cluster
|
98 |
const clustered = Array.from({ length: k }, (_, c) => []);
|
|
|
73 |
const n = embeddings.length, dim = embeddings[0].length;
|
74 |
let centroids = Array.from({ length: k }, () => embeddings[Math.floor(Math.random() * n)].slice());
|
75 |
let labels = new Array(n).fill(0);
|
76 |
+
for (let iter = 0; iter < 100; ++iter) {
|
77 |
for (let i = 0; i < n; ++i) {
|
78 |
let best = 0, bestDist = Infinity;
|
79 |
for (let c = 0; c < k; ++c) {
|
|
|
92 |
for (let c = 0; c < k; ++c) if (counts[c]) for (let d = 0; d < dim; ++d) centroids[c][d] /= counts[c];
|
93 |
}
|
94 |
// UMAP for 2D projection
|
95 |
+
const nNeighbors = Math.max(1, Math.min(lines.length - 1, 15));
|
96 |
+
const umap = new UMAP({ nComponents: 2, nNeighbors, minDist: 0.1 });
|
97 |
const proj = umap.fit(embeddings);
|
98 |
// Group lines by cluster
|
99 |
const clustered = Array.from({ length: k }, (_, c) => []);
|