November 2019
Intermediate to advanced
296 pages
7h 52m
English
In this section, we will look at how to classify using a random forest classifier. For instance, this code emulates the output of XOR logic by using RandomForestClassifier:
import { RandomForestClassifier } from 'machinelearn/ensemble';async function trainAndPredict() { // The 2-dimensional input const X = [ [0, 0], [0, 1], [1, 0], [1, 1] ]; // Target value for the output of XOR const y = [ 0, 1, 1, 0 ]; const model = new RandomForestClassifier(); model.fit(X, y); const result = model.predict(X); console.log(result);}trainAndPredict();
Simply passing the input data and target value to the model in the fit method gives you a trained model. Not all models in machinelearn.js use TensorFlow.js as the backend, but the ...
Read now
Unlock full access