mljs / random-forest

Random forest for classification and regression.
https://mljs.github.io/random-forest/
MIT License
61 stars 21 forks source link

Load model that was saved as JSON #29

Closed frodoCombs closed 3 years ago

frodoCombs commented 3 years ago

I'm really enjoying this library. Thank you for all your work!

At the moment, it is possible to train and save a random forest model with toJSON(), but I don't see how to load a saved model. It would be really useful to be able to load pre-trained models.

frodoCombs commented 3 years ago

In the p5.js world, this works:

let m;
function preload(){
   m = loadJSON('rf.json')
}
function setup(){
  rf = ML.RandomForestClassifier.load(m)
  let result = rf.predict(trainingSet)
  console.log(result)
}