Error when saving classifier: "TypeError: Converting circular structure to JSON"
I'm working through the documentation but unable to overcome this issue.
I try this:
var natural = require('natural');
classifier = new natural.BayesClassifier();
classifier.addDocument('i am long qqqq', 'buy');
classifier.addDocument('buy the q\'s', 'buy');
classifier.addDocument('short gold', 'sell');
classifier.addDocument('sell gold', 'sell');
classifier.train();
classifier.save('classifier.json', function(err, classifier) {});
I get this error:
TypeError: Converting circular structure to JSON
I've investigated and it's an issue with JSON.stringify, but I cannot figure out how to overcome it.
I also have this issue, haven't had any luck solving as of yet...
For me this works in latest version
I also have this issue.
I've investigated and it's an issue with JSON.stringify, but I cannot figure out how to overcome it.
Is it? The error message refers to properties in the object being bound via each other, something that is hard to resolve for a formatter.
The error refers to this code:
var data = JSON.stringify(this);
For me, the problem occurred only when I attempted to promisify the .save method, and this happens because if you do:
const { promisify } = require('util')
async function run() {
// training code here
const saveToJSON = promisify(classifier.save)
await saveToJSON()
}
The value/scope of this inside of the .save() method changes.