Classifier question
Hi,
I'm creating a bot application using natural. Classifying results have been very accurate until I started training it with some basic phrases:
const natural = require('natural');
const classifier = new natural.LogisticRegressionClassifier();
classifier.addDocument('who are you', 'name');
classifier.addDocument('what is your name', 'name');
classifier.addDocument('how old are you', 'age');
classifier.addDocument('how young are you', 'age');
classifier.addDocument('bye', 'farewell');
classifier.addDocument('see you', 'farewell');
classifier.addDocument('farewell', 'farewell');
classifier.train();
console.log(classifier.getClassifications('see you'));
output:
[ { label: 'name', value: 0.5 },
{ label: 'age', value: 0.5 },
{ label: 'farewell', value: 0.5 } ]
Am I doing something wrong?
Hi! When you get 0.5 in all your classifications, is because it was not able to compute the response. Basically, it means the intent "None" with score 1. About what is happenning... well, you pass "see you", and stemmed and tokenized into ['see', 'you']. After that, what is happening is that the stopwords are removed from your tokens, and guess what... there are 169 english stopwords, one is 'see' and other is 'you', so your input is converted to an empty array by the tokenizeAndStem. And when you pass an empty array of features to the classifier, it returns the default.
Makes sense. Thanks @jseijas
solved by classifier.setOptions({keepStops: true}); before adding documents.