JavaScript Machine Learning
npm install @jsmlt/jsmltThe JavaScript Machine Learning Toolkit, or JSMLT, is an open source JavaScript library for education in machine learning. It implements several well-known supervised learning algorithms in an understandable, modular and well-commented way. Furthermore, visualization examples are provided which allow you to explore the way different machine learning algorithms work. Ultimately, JSMLT is intended to provide students with a better learning experience when studying machine learning algorithms.
If you want to explore a visualization of the machine learning algorithms in JSMLT, check out visualml.io. It provides an interactive environment for using JSMLT's algorithms.
To install JSMLT into your npm project via npm, run
``bash`
npm install @jsmlt/jsmlt
> If you want to run this example without having to set up anything by yourself, check out the JSMLT examples repository. It includes the example below, and requires no further setup: it's ready to run!
`js
// Import JSMLT library
var jsmlt = require('@jsmlt/jsmlt');
// Training data
train_X = [[-1,-1], [-1,1], [1,1], [1,-1]];
train_y = [0, 0, 1, 1];
// Testing data
test_X = [[1,2], [1,-2], [-1,-2], [-1,2]];
// Create and train classifier
var clf = new jsmlt.Supervised.SVM.SVM({
kernel: new jsmlt.Kernel.Linear(),
});
clf.train(train_X, train_y);
// Make predictions on test data
console.log(clf.predict(test_X));
`
Running this simple example will output the classification result [1,1,0,0], meaning it classified the first two points as 0, and the second two points as 1.
: the documentation will then be available in the docs folder.$3
- Random Forest: JSMLT.Supervised.Trees.RandomForest
- Decision Tree: JSMLT.Supervised.Trees.DecisionTree
- Support Vector Machine (SVM): JSMLT.Supervised.SVM.SVM
- Perceptron: JSMLT.Supervised.Linear.Perceptron
- Neural Networks: JSMLT.Supervised.NeuralNetwork.FullyConnected
- k-nearest neighbors: JSMLT.Supervised.Neighbors.KNN
- Logistic Regression: JSMLT.Supervised.Neighbors.LogisticRegression$3
- k-means: JSMLT.Unsupervised.Neighbors.KMeans$3
- Linear kernel: JSMLT.Kernel.LinearKernel
- Gaussian (RBF) kernel: JSMLT.Kernel.GaussianKernel
- Polynomial kernel: JSMLT.Kernel.PolynomialKernel
- Sigmoid kernel: JSMLT.Kernel.SigmoidKernel$3
- Encode string or other type of labels to integers: JSMLT.Preprocessing.LabelEncoder$3
- Data set splitting: JSMLT.ModelSelection.trainTestSplit$3
- Iris dataset loading: JSMLT.Datasets.loadIris$3
- Accuracy metric for validation: JSMLT.Validation.Metrics.accuracy
- AUROC metric for validation: JSMLT.Validation.Metrics.auroc$3
- Classification boundaries for trained classifier: JSMLT.Classification.Boundaries`