Skip to content

Instantly share code, notes, and snippets.

Avatar

Robert Gove rpgove

View GitHub Profile
@rpgove
rpgove / .block
Last active Jan 10, 2023
Group-in-a-box layout
View .block
license: gpl-3.0
height: 302
@rpgove
rpgove / .block
Last active Jan 10, 2023
Force-directed layout
View .block
license: gpl-3.0
height: 600
@rpgove
rpgove / README.md
Last active Dec 25, 2022
Using the elbow method to determine the optimal number of clusters for k-means clustering
View README.md

K-means is a simple unsupervised machine learning algorithm that groups a dataset into a user-specified number (k) of clusters. The algorithm is somewhat naive--it clusters the data into k clusters, even if k is not the right number of clusters to use. Therefore, when using k-means clustering, users need some way to determine whether they are using the right number of clusters.

One method to validate the number of clusters is the elbow method. The idea of the elbow method is to run k-means clustering on the dataset for a range of values of k (say, k from 1 to 10 in the examples above), and for each value of k calculate the sum of squared errors (SSE). Like this:

var sse = {};
for (var k = 1; k <= maxK; ++k) {
    sse[k] = 0;
    clusters = kmeans(dataset, k);
    clusters.forEach(function(cluster) {

mean = clusterMean(cluster);

@rpgove
rpgove / .block
Last active Aug 30, 2020
Automatically Finding Better Force Directed Layout Parameters
View .block
license: gpl-3.0
height: 600
scrolling: no
border: yes
@rpgove
rpgove / .block
Last active Jul 29, 2020
EuroVis 2019 Twitter interaction network
View .block
license: bsd-3-clause
height: 600
@rpgove
rpgove / .block
Last active Jan 16, 2020
Force Directed Layout Quality Convergence
View .block
license: gpl-3.0
height: 600
scrolling: no
border: yes
@rpgove
rpgove / .block
Last active Dec 27, 2019 — forked from mbostock/.block
Spiral Treemap
View .block
border: no
height: 600
license: gpl-3.0
@rpgove
rpgove / README.md
Last active Dec 27, 2019
Showing tooltips above a different element with d3-tip
View README.md

Sometimes you need to show a tooltip over a different element than the one firing the mouseover event. Fortunately, d3-tip allows you to do that by passing an SVGElement as the second parameter to tip.show(). Like this:

tip.show(data, target)

This SVGElement will be the new target of the tooltip.

@rpgove
rpgove / .block
Created Nov 19, 2018
d3-force-reuse speed comparison
View .block
license: gpl-3.0
height: 600
@rpgove
rpgove / data.tsv
Last active May 5, 2019
Force-Directed Scatterplot
View data.tsv
sepalLength sepalWidth petalLength petalWidth species
5.1 3.5 1.4 0.2 setosa
4.9 3.0 1.4 0.2 setosa
4.7 3.2 1.3 0.2 setosa
4.6 3.1 1.5 0.2 setosa
5.0 3.6 1.4 0.2 setosa
5.4 3.9 1.7 0.4 setosa
4.6 3.4 1.4 0.3 setosa
5.0 3.4 1.5 0.2 setosa
4.4 2.9 1.4 0.2 setosa