Last active
December 29, 2016 10:45
-
-
Save adrianmcli/0c8216e3d7b153f8ff07a72e6fd70053 to your computer and use it in GitHub Desktop.
Naive Bayes classifier basic demo with React and Natural
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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