Random Forest
A random forest classifier. A random forest is a meta estimator that fits a number of decision tree classifiers on various sub-samples of the dataset and use averaging to improve the predictive accuracy and control over-fitting.
Modeled after scikit-learn's RandomForestClassifier.
Installation
$ npm install random-forest-classifier
Example
var fs = RandomForestClassifier = RandomForestClassifier; var data = "length":51 "width":35 "petal_length":14 "petal_width":02 "species":"setosa" "length":65 "width":3 "petal_length":52 "petal_width":2 "species":"virginica" "length":66 "width":3 "petal_length":44 "petal_width":14 "species":"versicolor" ...; var testdata = "length":63 "width":25 "petal_length":5 "petal_width":19 //"species":"virginica" "length":47 "width":32 "petal_length":13 "petal_width":02 //"species":"setosa" ...; var rf = n_estimators: 10; rf;
Usage
Options
n_estimators
: integer, optional (default=10) The number of trees in the forest.
example
var rf = n_estimators: 20;
rf.fit(data, features, target, function(err, trees){})
Build a forest of trees from the training set (data, features, target).
parameters
data
: training data arrayfeatures
: ifnull
it defaults to all features except the target, otherwise it only uses the array of features passedtarget
: the target feature
example
var rf = n_estimators: 20; rf;
rf.predict(data, trees)
The predicted class of an input sample is computed as the majority prediction of the trees in the forest.
parameters
data
: input sampletrees
: the forest of trees outputted byrf.fit
example
var rf = n_estimators: 20; rf;