npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

callidusts

v1.0.24

Published

A collection of machine-learning algorithms.

Downloads

42

Readme

CallidusTS

A collection of machine-learning algorithms.

Notes:

The object that you require has the objects Regress, Classify, Cluster, and Tools.  

Regress has

Classify has

Cluster has

Tools has

Regress

These are algorithms for finding the best fit line between arrays of inputs/outputs based on a variety of functions.

Initializing

Input and output must both be arrays of numbers.

  • Polynomial: constructor([input = [], output = [], degree = 2])
  • Others: constructor([input = [], output = []])

Training

Training:

  • All: train()

Predicting

Predicting:

  • All: predict(x)

Getting error and correlation

Error:

  • All: findStandardError()

Correlation:

  • All: findCorrelation()

Putting it all together

const { Regress } = require("callidusjs");

var input = [1, 2, 3, 4, 5];
var output = [2, 4, 8, 16, 32];

var model = new Regress.ExponentialAB(input, output);

console.log(model.train().predict(6)); //=> 64

Classify

These are algorithms for categorizing arrays of input data into different classes based on a variety of methods.

Initializing

For KNearestNeighbors and Perceptron, input must be an array of arrays of numbers, and output must be an array of numbers. For the Naive Bayes classifiers, the input must be an array of arrays of anything, and output must be an array of anything. Remember, when using the bayesian classifiers, you must not provide data with values based on index in the inputs as with the other classifiers; rather, it's recommended to use an array of unique feature names (like strings) so that the classifiers can see whether/how many times each of these features occurs in a given input. This works especially well for NLP, where you can pass an array of arrays of tokens or stems directly into these classifiers.

  • KNearestNeighbors: constructor([input = [], output = []])
  • NearestCentroid: constructor([input = [], output = []])
  • Perceptron: constructor([input = [], output = [], options = {a: 1}]) where a is the learning rate
  • Bernoulli: constructor([input = []], output = []])
  • Multinomial: constructor([input = []], output = []])
  • ZeroR: constructor([output = []])
  • OneR: constructor([input = [], output = []])

Training

Batch training:

  • KNearestNeighbors: doesn't need to be trained
  • NearestCentroid: train()
  • Perceptron: train(gamma[, maxIterations = 10000])
  • Bernoulli: train()
  • Multinomial: train()
  • ZeroR: doesn't need to be trained
  • OneR: train()

Online training (for any not specified here, just use the usual train method):

  • Perceptron: trainFor([iterations = 1])

Predicting

Predicting:

  • KNearestNeighbors: predict(x[, k = 1])
  • NearestCentroid: predict(x)
  • Perceptron: predict(x[, bias = 0])
  • Bernoulli: predict(x)
  • Multinomial: predict(x)
  • ZeroR: predict()
  • OneR: predict(x)

Putting it all together

Example 1:

const { Classify } = require("callidusjs");

var input = [
    [1, 1, 1],
    [1, 0, 0],
    [0, 0, 0],
    [0, 1, 1]
];
var output = [1, 1, 0, 0];

var model = new Classify.Weights.Perceptron(input, output);

model.train(0.1); // gamma is 0.1, max iterations is not specified (so 10000)

console.log(model.predict([1, 0, 1])); //=> 1, because the first element of the inputs completely determines output

 

Example 2:

const { Classify, Tools } = require("callidusjs");

// aliases for the types (for readability and ease-of-use; the types are only so verbose in an effort to organize)
const Stemmer = Tools.Porter2;
const Classifier = Classify.NaiveBayes.Multinomial;

var input = [
    Stemmer.tokenize("This is certainly, very surely an english sentence with plenty of english words, and I hope that the classifier will be able to label it as an english sentence because that's exactly what it is."),
    Stemmer.tokenize("C’est certainement, très sûrement, une phrase français avec beaucoup de mots anglais, et j’espère que le classificateur pourra la qualifier de phrase français, car c’est exactement ce que c’est.")
];
var output = [
    'english',
    'french'
];

var model = new Classifier(input, output);

model.train();

console.log(model.predict(Stemmer.tokenize("Another sentence (guess what language this is in!)"))); //=> english
console.log(model.predict(Stemmer.tokenize("Une autre phrase (devine en quelle langue ceci est!)"))); //=> french

Cluster

These are unsupervised learning techniques that are made for clustering data.

Initializing

As these algorithms are unsupervised, so you only provide the input (an array of arrays of numbers) to them.

  • KMeans: constructor([input = []])
  • KMedians: constructor([input = []])

Training

Batch training:

  • KMeans: train(k[, maxIterations = 10000])
  • KMedians: train(k[, maxIterations = 10000])

Online training (for any not specified here, just use the usual train method):

  • KMeans: trainFor(k[, iterations = 1])
  • KMedians: trainFor(k[, iterations = 1])

Getting the output

Centroids:

  • KMeans: the centroids property, an array of arrays of numbers
  • KMedians: the centroids property, an array of arrays of numbers

Tools

Porter

A classic stemming algorithm. Use the static methods stem(word) to find the stem of a word, or tokenize(text[, punctuation = puncRegex]), where the second optional argument is a regex of items to remove (default is all punctuation).

Porter2

The newer, revised version of Porter. It has exactly the same interface as Porter for stemming and tokenizing.

Saving and Loading Models

All models can be transformed to and from JSON-format strings using these instance methods:

  • Saving: exportJSON([jsonFormattingSpaces = 0])
  • Loading: importJSON(jsonOb)

Note: the method importJSON will automatically set applicable algorithms' trained property to true, whether the model that the state was saved from was trained or not.