{"id":15079,"library":"apparatus","title":"Apparatus Machine Learning Routines","description":"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.","status":"abandoned","version":"0.0.10","language":"javascript","source_language":"en","source_url":"https://github.com/NaturalNode/apparatus","tags":["javascript","machine","learning","ml","classifier","clustering","bayes","k-means","logistic"],"install":[{"cmd":"npm install apparatus","lang":"bash","label":"npm"},{"cmd":"yarn add apparatus","lang":"bash","label":"yarn"},{"cmd":"pnpm add apparatus","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Apparatus uses deep CommonJS imports. The main `apparatus` module does not export algorithms directly.","wrong":"import { BayesClassifier } from 'apparatus';\nimport { BayesClassifier } from 'apparatus/lib/classifier/bayes_classifier';","symbol":"BayesClassifier","correct":"const bayes = require('apparatus/lib/classifier/bayes_classifier');\nconst classifier = new bayes.BayesClassifier();"},{"note":"Some modules export a named property, `KMeans` in this case. ESM imports are not supported.","wrong":"import { KMeans } from 'apparatus/lib/clustering/k_means';\nconst KMeans = require('apparatus/lib/clustering/k_means');","symbol":"KMeans","correct":"const KMeans = require('apparatus/lib/clustering/k_means').KMeans;\nconst k_means = new KMeans();"},{"note":"Similar to KMeans, LogisticRegression is a named export from a deep path within the CommonJS module structure.","wrong":"import LogisticRegression from 'apparatus/lib/regression/logistic_regression';","symbol":"LogisticRegression","correct":"const LogisticRegression = require('apparatus/lib/regression/logistic_regression').LogisticRegression;\nconst regression = new LogisticRegression();"}],"quickstart":{"code":"const KMeans = require('apparatus/lib/clustering/k_means').KMeans;\n\n// Sample data: each inner array is a data point (e.g., [x, y])\nconst data = [\n  [1, 1], [1.5, 2],\n  [5, 7], [8, 8],\n  [1, 0.8], [9, 11]\n];\n\nconst k_means = new KMeans();\n\n// Configure K-Means algorithm\n// k: number of clusters\n// iterations: max iterations\n// threshold: convergence threshold\nk_means.k = 2;\nk_means.iterations = 100;\nk_means.threshold = 0.001;\n\n// Train the K-Means model\nk_means.train(data, (error, result) => {\n  if (error) {\n    console.error('K-Means training error:', error);\n    return;\n  }\n  console.log('K-Means Clusters:');\n  result.clusters.forEach((cluster, index) => {\n    console.log(`  Cluster ${index + 1} Centroid: [${cluster.centroid.join(', ')}]`);\n    console.log(`  Points in Cluster ${index + 1}:`, cluster.points);\n  });\n});","lang":"javascript","description":"Demonstrates training a K-Means clustering model with sample 2D data, including setup and output of clusters and centroids."},"warnings":[{"fix":"Avoid using 'apparatus' for new projects. Consider actively maintained alternatives like `ml-matrix`, `scikit-learn` (via Python bridge), or `tensorflow.js` for machine learning in Node.js.","message":"The 'apparatus' package has been abandoned since its last commit in March 2012. It is not maintained and is highly unlikely to be compatible with modern Node.js versions (e.g., Node.js 14+). Expect runtime errors related to deprecated APIs, missing polyfills, or C++ native module incompatibilities if any are present.","severity":"breaking","affected_versions":">=0.0.10"},{"fix":"Always use `const MyClass = require('apparatus/lib/path/to/module').MyClass;` for all imports.","message":"Apparatus relies exclusively on CommonJS `require()` syntax and is not designed for ES Modules (ESM). Attempting to use `import` statements will result in a `SyntaxError` unless a transpilation step (e.g., Babel) is configured or Node.js's `--experimental-modules` flag is used with care, which is not recommended for an abandoned library.","severity":"gotcha","affected_versions":">=0.0.10"},{"fix":"For text processing, consider the 'natural' package (which uses apparatus internally but adds NLP layers) or other specialized libraries. For other data types, perform necessary feature extraction and vectorization externally.","message":"The package provides low-level numerical algorithms. It does not include features for natural language processing (NLP), image processing, or complex data pre-processing. Users are expected to prepare their data into arrays of numbers or vectors before passing them to apparatus algorithms.","severity":"gotcha","affected_versions":">=0.0.10"},{"fix":"Migrate to a currently maintained machine learning library. If migration is not immediately feasible, thoroughly audit the codebase for security concerns and isolate its usage to minimize risk.","message":"Due to its abandonment, 'apparatus' lacks security updates, bug fixes, or performance improvements. Using it in production environments carries significant risks, including potential vulnerabilities or unexpected behavior with evolving JavaScript runtimes.","severity":"deprecated","affected_versions":">=0.0.10"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Instantiate the class using `const k_means = new KMeans();` instead of `const k_means = KMeans();`.","cause":"Attempting to call the `KMeans` constructor (or similar algorithm classes) as a function without the `new` keyword.","error":"TypeError: Class constructor KMeans cannot be invoked without 'new'"},{"fix":"Ensure 'apparatus' is installed (`npm install apparatus`) and verify the exact path `require('apparatus/lib/...')` matches the structure within `node_modules`. Paths are case-sensitive.","cause":"Incorrect import path or the 'apparatus' package is not installed correctly or is not accessible from the current working directory.","error":"Error: Cannot find module 'apparatus/lib/clustering/k_means'"},{"fix":"Replace `import` statements with CommonJS `require()` calls: `const KMeans = require('apparatus/lib/clustering/k_means').KMeans;`.","cause":"Attempting to use ES module `import` syntax (`import { KMeans } from 'apparatus/lib/...'`) in a Node.js environment that expects CommonJS modules.","error":"SyntaxError: Cannot use import statement outside a module"}],"ecosystem":"npm"}