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. OpenCV中Mat数据的访问报错

    最近再写一段程序的时候,要访问Mat中的元素.在定义Mat型数据的时候,用 Mat ObjectPoints(48,3,CV_32FC1,0) 对其进行初始化后,用at进行访问时报内存错误. Mat ...

  2. 在Windows下如何创建指定的虚拟环境

    前几天给大家分享了如何在默认的情况下创建虚拟环境,没来得及上车的伙伴,可以戳这篇文章:在Windows下如何创建虚拟环境(默认情况下).今天小编给大家分享一下,如何创建的指定的Python环境. 创建 ...

  3. Linux系统中命令提示符解释-Linux中命令格式、分类-bash中的快捷键

    1.命令提示符 [root@mysqlserver01 opt]# [root@mysqlserver01 ~]# root 当前用户名 @ 固定的(格式) mysqlserver01 主机名 opt ...

  4. thinkphp3.2.3 隐藏url上home模块以及index.php文件

    1.去掉Home index.php 添加如下代码 define('BIND_MODULE', 'Home'); 这时就隐藏了url中的Home 2.去掉index.php thinkphp3.2.3 ...

  5. 洛谷 P2309 loidc,卖卖萌

    P2309 loidc,卖卖萌 题目背景 Loidc萌萌哒. 他最近一直在靠卖萌追求他的真爱——vivym,经过几轮攻势后vivym酱眼看就要被他所攻略.擅长数据结构的vivym决定利用强大的数据结构 ...

  6. msp430在ccsv5下出现的问题总结

    一.内存问题 问题描写叙述,报错: program will not fit into available memory.  placement with alignment fails for se ...

  7. 记真实自己,炫精彩人生---《爱记》app使用体验

    真的有款神器吗,能找到合适的Ta,能秀出自己的新生活,能让自己的心情舒爽,有,体验了下.就是爱记.果粉的福利. [爱记]是集心情记录.分享.评价与交流于一体的工具,TA是你心灵休憩的港湾,也是你记忆放 ...

  8. CI框架源代码阅读笔记6 扩展钩子 Hook.php

    CI框架同意你在不改动系统核心代码的基础上加入或者更改系统的核心功能(如重写缓存.输出等). 比如,在系统开启hook的条件下(config.php中$config['enable_hooks'] = ...

  9. 【LeetCode-面试算法经典-Java实现】【121-Best Time to Buy and Sell Stock(最佳买卖股票的时间)】

    [121-Best Time to Buy and Sell Stock(最佳买卖股票的时间)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Say you have ...

  10. CentOS下编译安装Apache

    与Apache 2.2.x相比,Apache 2.4.x提供了很多性能方面的提升,包括支持更大流量.更好地支持云计算.利用更少的内存处理更多的并发等.除此之外,还包括性能提升.内存利用.异步 I/O的 ...