In this lesson, we will learn how to train a Naive Bayes classifier or a Logistic Regression classifier - basic machine learning algorithms - in order to classify text into categories.

var natural = require('natural');
var classifier = new natural.BayesClassifier(); var trainingData = [
{text: 'RE: Canadian drugs now on sale', label: 'spam'},
{text: 'Earn more from home', label: 'spam'},
{text: 'Information now available!!!', label: 'spam'},
{text: 'Earn easy cash', label: 'spam'},
{text: 'Your business trip is confirmed for Monday the 4th', label: 'notspam'},
{text: 'Project planning - next steps', label: 'notspam'},
{text:'Birthday party next weekend', label: 'notspam'},
{text: 'Drinks on Monday?', label: 'notspam'}
]; var testData = [
{text: 'Drugs for cheap', label: 'spam'},
{text: 'Next deadline due Monday', label: 'notspam'},
{text: 'Meet me at home?', label: 'notspam'},
{text: 'Hang out with someone near you', label: 'spam'}
]; trainingData.forEach(function(item){
classifier.addDocument(item.text, item.label);
}); classifier.train(); testData.forEach(function(item){
var labelGuess = classifier.classify(item.text);
console.log("\n");
console.log(item.text);
console.log("Label:", labelGuess);
console.log(classifier.getClassifications(item.text));
});

[Javascript] Classify text into categories with machine learning in Natural的更多相关文章

  1. [Javascript] Classify JSON text data with machine learning in Natural

    In this lesson, we will learn how to train a Naive Bayes classifier and a Logistic Regression classi ...

  2. A Gentle Guide to Machine Learning

    A Gentle Guide to Machine Learning Machine Learning is a subfield within Artificial Intelligence tha ...

  3. How do I learn machine learning?

    https://www.quora.com/How-do-I-learn-machine-learning-1?redirected_qid=6578644   How Can I Learn X? ...

  4. 100 Most Popular Machine Learning Video Talks

    100 Most Popular Machine Learning Video Talks 26971 views, 1:00:45,  Gaussian Process Basics, David ...

  5. [C5] Andrew Ng - Structuring Machine Learning Projects

    About this Course You will learn how to build a successful machine learning project. If you aspire t ...

  6. Machine Learning for Developers

    Machine Learning for Developers Most developers these days have heard of machine learning, but when ...

  7. What is machine learning?

    What is machine learning? One area of technology that is helping improve the services that we use on ...

  8. Machine Learning and Data Mining(机器学习与数据挖掘)

    Problems[show] Classification Clustering Regression Anomaly detection Association rules Reinforcemen ...

  9. [C2P2] Andrew Ng - Machine Learning

    ##Linear Regression with One Variable Linear regression predicts a real-valued output based on an in ...

随机推荐

  1. Word 操作组件介绍 - Spire.Doc

    http://www.cnblogs.com/liqingwen/p/5898368.html

  2. apiCloud如何打开新页面的同时,关掉当前页

    方法很多,只要不同时open.close都可行.给你一个简单的方式: api.addEventListener({ name:'viewdisappear' },function(){ api.clo ...

  3. nginx假死导致的问题回顾

    背景: 网络大致拓扑型 定位到一台Nginx节点于凌晨Timewait异常,等到6K. 进程异常,ngx_http_realtime_request模块错误 错误日志: 2017/02/24 00:0 ...

  4. PowerDesigner删除外键关系,而不删除外键列[转] 及编码格式

    PowerDesigner删除外键关系,而不删除外键列[转]  数据库 database  -> generate database ->format 设置为utf-8 PowerDesi ...

  5. customErrors 元素(ASP.NET 设置架构)

    1.适用版本:.NET Framework 4 2.元素定义:为 ASP.NET 应用程序提供有关自定义错误消息的信息. 可以在应用程序文件层次结构中的任意级别上定义 customErrors 元素. ...

  6. org.xml.sax.SAXParseException: Content is not allowed in prolog

    sax错误:org.xml.sax.SAXParseException: Content is not allowed in prolog解决  标签: org. xml. sax. saxparse ...

  7. vue 指令的用法

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Fedora27 安装Adobe Flash Player PPAPI与NPAPI实现Firefox和Chromium视频播放

    一.Adobe Flash Player PPAPI与NPAPI有什么区别我们在打开网页视频时有时会弹出没有安装Flash插件的提示,此时就无法观看视频.Adobe Flash Player是浏览器显 ...

  9. node.学习笔记(关于http2的讲解)

    个人总结:读完这篇文章需要30分钟 http2部分很有学习价值,可以好好看.  用node搭建TCP服务器 用node搭建HTTP服务器 用node文件fs模块对文件读取,并用流的方式写入 用url路 ...

  10. MOOC使用心得

    1. Mooctest 使用心得 慕测平台是编程类考试和练习的服务平台,教师可以轻松监管考试流程,学生可以自由练习编程.系统负责编程练习的自动化评估及可视化展现,配合当下红火的MOOC慕课课程,慕测平 ...