Skip to content

Instantly share code, notes, and snippets.

@adrianmcli
Last active December 29, 2016 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianmcli/0c8216e3d7b153f8ff07a72e6fd70053 to your computer and use it in GitHub Desktop.
Save adrianmcli/0c8216e3d7b153f8ff07a72e6fd70053 to your computer and use it in GitHub Desktop.
Naive Bayes classifier basic demo with React and Natural
import React from 'react';
import natural from 'natural';
class App extends React.Component {
constructor() {
super();
// Create a classifier instance
const classifier = new natural.BayesClassifier();
// Train the classifier
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();
// Assign it to the component instance
this.classifier = classifier;
}
render() {
// The following two lines actually work as expected!
console.log(this.classifier.classify('i am short silver'), '<- should be sell');
console.log(this.classifier.classify('i am long copper'), '<- should be buy');
return (
<div>pay no attention to me!</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment