How to use the simple-statistics/src/ckmeans.default function in simple-statistics

To help you get started, we’ve selected a few simple-statistics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TerriaJS / terriajs / lib / Models / LegendHelper.js View on Github external
}
  }

  if (method === "quantile") {
    // One issue is we don't check to see if any values actually lie within a given quantile, so it's bad for small datasets.
    for (i = 0; i < binCount; i++) {
      binColors.push({
        upperBound: quantile(numericalValues, (i + 1) / binCount),
        colorArray: getColorArrayFromColorGradient(
          colorGradient,
          i / (binCount - 1)
        )
      });
    }
  } else if (method === "ckmeans") {
    var clusters = ckmeans(numericalValues, binCount);
    // Convert the ckmeans format [ [5, 20], [65, 80] ] into our format.
    for (i = 0; i < clusters.length; i++) {
      if (
        i > 0 &&
        clusters[i].length === 1 &&
        clusters[i][0] === clusters[i - 1][clusters[i - 1].length - 1]
      ) {
        // When there are few unique values, we can end up with clusters like [1], [2],[2],[2],[3]. Let's avoid that.
        continue;
      }
      binColors.push({
        upperBound: clusters[i][clusters[i].length - 1]
      });
    }
    if (binColors.length > 1) {
      for (i = 0; i < binColors.length; i++) {