Apparatus Machine Learning Routines

0.0.10 · abandoned · verified Tue Apr 21

Apparatus is an abandoned Node.js package (last updated in 2012, current version 0.0.10) providing a collection of low-level machine learning algorithms. It focuses on numerical input, primarily arrays of numbers and vectors, and is not designed for direct text or natural language processing. Instead, it serves as a foundational library for other projects like the 'natural' package, which adds a layer of text feature extraction. Due to its age, it primarily uses CommonJS modules and is not compatible with modern Node.js ESM-only environments without transpilation or specific configuration. Its lack of maintenance means it should be approached with caution for new projects.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates training a K-Means clustering model with sample 2D data, including setup and output of clusters and centroids.

const KMeans = require('apparatus/lib/clustering/k_means').KMeans;

// Sample data: each inner array is a data point (e.g., [x, y])
const data = [
  [1, 1], [1.5, 2],
  [5, 7], [8, 8],
  [1, 0.8], [9, 11]
];

const k_means = new KMeans();

// Configure K-Means algorithm
// k: number of clusters
// iterations: max iterations
// threshold: convergence threshold
k_means.k = 2;
k_means.iterations = 100;
k_means.threshold = 0.001;

// Train the K-Means model
k_means.train(data, (error, result) => {
  if (error) {
    console.error('K-Means training error:', error);
    return;
  }
  console.log('K-Means Clusters:');
  result.clusters.forEach((cluster, index) => {
    console.log(`  Cluster ${index + 1} Centroid: [${cluster.centroid.join(', ')}]`);
    console.log(`  Points in Cluster ${index + 1}:`, cluster.points);
  });
});

view raw JSON →