
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@jbeuckm/k-means-js
Advanced tools
A basic Javascript implementation of the cluster analysis algorithm.
A basic Javascript implementation of the [cluster analysis] 1 algorithm.
npm i @jbeuckm/k-means-js --save
The normalizer will scale numerical data between [0,1] and will generate n outputs of either zero or one for discrete data, eg. category.
// Tell the normalizer about the category field.
const params = {
category: "discrete",
};
// Category is a discrete field with two possible values.
// Value is a linear field with continuous possible values.
const data = [
{
category: "a",
value: 25,
},
{
category: "b",
value: 7.6,
},
{
category: "a",
value: 28,
},
];
import { dataset } from "@jbeuckm/k-means-js";
// Get ranges for normalizing and denormalizing the data
const ranges = dataset.findRanges(params, data);
// Optionally, set the relative importance of one or more fields
// *The default weight for any field is one.*
const weights = { category: 2 };
const normalized = dataset.normalize(data, ranges, weights);
// This non-normalized sample data with n=k is a pretty awful example.
var points = [
[0.1, 0.2, 0.3],
[0.4, 0.5, 0.6],
[0.7, 0.8, 0.9],
];
var k = 3;
import kmeans from "@jbeuckm/k-means-js";
const means = kmeans.cluster(points, k, console.log);
The call to cluster() will find the data's range in each dimension, generate k=3 random points, and iterate until the means are static.
The method described by Pham, et al. is implemented. The algorithm evaluates K-means repeatedly for different values of K, and returns the best (guess) value for K as well as the set of means found during evaluation.
import { phamBestK } from "@jbeuckm/k-means-js";
const maxKToTest = 10;
const result = phamBestK.findBestK(points, maxKToTest);
console.log("this data has " + result.K + " clusters");
console.log("cluster centroids = " + result.means);
Denormalization can be used to show the means discovered:
for (let i = 0, l = result.means.length; i < l; i++) {
console.log(dataset.denormalizeDatum(result.means[i], ranges));
}
FAQs
A basic Javascript implementation of the cluster analysis algorithm.
The npm package @jbeuckm/k-means-js receives a total of 5 weekly downloads. As such, @jbeuckm/k-means-js popularity was classified as not popular.
We found that @jbeuckm/k-means-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.