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. Linux PuTTY 更改字体

    Linux PuTTY默认的字体比较小看着比较不舒服,Linux PuTTY的字体更改与Windows下的设置有所不同 1.Linux PuTTY默认的字体 ,Font used for ordina ...

  2. python yield学习

    yield的功能类似于return,但是不同之处在于它返回的是生成器. 生成器生成器是通过一个或多个yield表达式构成的函数,每一个生成器都是一个迭代器(但是迭代器不一定是生成器). 如果一个函数包 ...

  3. GridView单元格取值显示为 

    在通过GridView取一个单元格(cell)的值时,数据库中为NULL,而页面上显示为空格.发现通过gridview.cell[i].text取出来的值为 ,导致获取数据出现问题. 解决方法: 一. ...

  4. 解决MyEclipse中安装或升级ADT之后SDK Target无法显示的问题

        故障现象,在MyEclipse里面安装完最新的android sdk和ADT之后,无法新建项目,Build Target为空,显示一直在loading.即如下面图里面显示的,Target Na ...

  5. https soap链接示例

    1.先安装soap扩展sudo yum install php-soap 2.安装openssL 3.function  issure($sn){//通过soap链接接口  进行确认是否是正确的sn码 ...

  6. LINQ to SQL活学活用(1):这要打破旧观念

    程序架构 如今比較经典的架构,看看以下图片. 怎样实现 在一个N层应用程序中我们怎样使用LINQ to SQL呢?这给刚刚入门的朋友的确是个难题,使用LINQ to SQL就是ORM技术,能够非常轻松 ...

  7. 【LeetCode-面试算法经典-Java实现】【05-Longest Palindromic Substring(最大回文字符串)】

    背景 近期開始研究算法,于是在leetcode上做算法题,第五题Longest Palindromic Substring便是关于回文子串的. 什么是回文字串 回文字符串是指将该字符串前后颠倒之后和该 ...

  8. Mysql第八天 分区与分表

    分区表 主要提供例如以下的特性,或者适合如此场景: 数据量非常大, 或者仅仅有表中最后的部分有热点数据.其它均为历史数据 分区表数据更easy维护,能够对独立的分区删除等操作 分区表的数据能够分布在不 ...

  9. Linux下Oracle的sqlplus中上下左右退格键无法使用

    一.配置yum源并安装readline* 配置本地yum 1.挂载光盘 mount /dev/cdrom /mnt/media 2,新建本地yun源的配置文件 vi /etc/yum.repos.d/ ...

  10. hdu5288 OO’s Sequence 二分 多校联合第一场

    OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...