Skip to content

Instantly share code, notes, and snippets.

@nickcherry
Created May 10, 2017 02:47
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 nickcherry/9c48423003b99785367623ec613771f2 to your computer and use it in GitHub Desktop.
Save nickcherry/9c48423003b99785367623ec613771f2 to your computer and use it in GitHub Desktop.
const classifier = new BayesClassifier();
classifier.train('BarackObama', 'Fighting climate change with solar power creates jobs.');
classifier.train('elonmusk', 'Turns out ExxonMobil not 100% forthcoming about climate change');
classifier.train('elonmusk', 'Yeah, climate change should really be considered a centrist issue, as it affects everyone.');
classifier.stemCounts
/*
{
'100': 1,
turn: 1,
out: 1,
exxonmobil: 1,
not: 1,
forthcom: 1,
about: 1,
climat: 3,
chang: 3,
yeah: 1,
should: 1,
realli: 1,
be: 1,
consid: 1,
a: 1,
centrist: 1,
issu: 1,
as: 1,
it: 1,
affect: 1,
everyon: 1,
fight: 1,
with: 1,
solar: 1,
power: 1,
creat: 1,
job: 1
}
*/
classifier.stemCountsByCategory
/*
{
elonmusk: {
'100': 1,
turn: 1,
out: 1,
exxonmobil: 1,
not: 1,
forthcom: 1,
about: 1,
climat: 2,
chang: 2,
yeah: 1,
should: 1,
realli: 1,
be: 1,
consid: 1,
a: 1,
centrist: 1,
issu: 1,
as: 1,
it: 1,
affect: 1,
everyon: 1
},
BarackObama: {
fight: 1,
climat: 1,
chang: 1,
with: 1,
solar: 1,
power: 1,
creat: 1,
job: 1
}
}
*/
classifier.documentCountsByCategory
/*
{
elonmusk: 2,
BarackObama: 1
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment