harthur / classifier Goto Github PK
View Code? Open in Web Editor NEWBayesian classifier with Redis backend
License: MIT License
Bayesian classifier with Redis backend
License: MIT License
🍻
Hi,
First of all, thank you for a really helpful Naive Bayes Classifier library. I tried to implement in Node.js but also having the same problem with your library.
I have a dataset of 1212 sets and 294419 wordsets generated by your library. I used socket.io to handle websocket connections from clients and it always returning result at the first classifying attempt, however when attempting to classify after the first try, it always hangs.
If using a lower quantity of data like the example you posted, it was successful.
To make it clear, here are some codes I used:
io.sockets.on('connection', function(socket) {
// Classify
socket.on('classify', function(data) {
if(typeof data.namespace == 'string' && typeof data.keywords == 'string') {
console.log('Classifying: ' + data.keywords);
var start = new Date().getTime();
bayes.classify(data.keywords, function(cat) {
console.log('Classified: ' + cat);
var elapsed = new Date().getTime() - start;
if(typeof cat == 'string' && cat !== '' && cat != 'unclassified') {
var result = {
classifyStatus: {
code: 200,
msg: 'Success',
timing: elapsed
},
text: data.keywords,
category: cat
};
console.log(result);
socket.emit('classifyCategory', result);
}
else {
console.log('Unclassified');
socket.emit('classifyCategory', {
classifyStatus: {
code: 200,
msg: 'Cannot classify into any categories',
timing: elapsed
},
text: data.keywords,
category: 'unclassified'
});
}
});
}
else {
console.log('Unclassified - no data from client');
socket.emit('classifyCategory', {
trainStatus: {
code: 500,
msg: 'Failed',
timing: 0
},
text: data.keywords,
category: ''
});
}
});
});
Sadly does not support UTF-8. The problem lies here:
getWords : function(doc) {
if (_(doc).isArray()) {
return doc;
}
var words = doc.split(/\W+/);
return _(words).uniq();
}
doc.split(/\W+/);
does not seem to work for UTF-8
Here is an example with Cyrilic language (like Russian):
"Надежда за обич еп.36 Тест".split(/\W+/);
This returns:
[ "", "36", "" ]
Instead should return something like this:
[ "Надежда", "за", "обич", "еп", "36", "Тест"]
I was looking for fix, but ended up here:
http://stackoverflow.com/questions/280712/javascript-unicode-regexes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.