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. Delegates, Events, and Anonymous Methods 委托、事件与匿名方法

    http://www.cnblogs.com/r01cn/archive/2012/11/30/2795977.html

  2. SSH之IDEA2017整合Struts2+Spring+Hibernate

    转自:https://blog.csdn.net/sysushui/article/details/68937005

  3. LINQ查询基础

    一.什么是LINQ LINQ是Language Integrate Query的缩写,意为语言集成查询,是微软在.Net Framework 4.5版中推出的主要特性之一. 它为开发人员提供了统一的数 ...

  4. C/C++(C++拷贝构造器,赋值运算符重载)

    拷贝构造器 由己存在的对象,创建新对象.也就是说新对象,不由构造器来构造,而是由拷贝构造器来完成.拷贝构造器的格式是固定的. class 类名 { 类名(const 类名 & another) ...

  5. BZOJ2636: crisis(可持久化线段树)

    传送门: 解题思路: 题目描述是一大坑点,cancel后面是直接加ask或者redo的. 那么就可以愉快地可持久化了. 注意需要支持区间修改,那么就只需要在再次更新这个点的时候将标记储存在新的儿子中. ...

  6. 【RHEL7/CentOS7基本配置】

    目录 @ 相比于6.x的版本,Rhel7/CentOS7增加或改进了以下7大特性. 1.身份管理 kerberos的跨平台信任机制:kerberos将完全兼容微软活动目录,实现完全使用活动目录进行认证 ...

  7. 搭建专属于自己的Leanote云笔记本

    搭建专属于自己的Leanote云笔记本 Leanote 依赖 MongoDB 作为数据存储,下面开始安装 MongoDB: 下载 MongoDB 进入 /home 目录,并下载 MongoDB: cd ...

  8. @Mapper 和 @MapperScan 区别

    1.@Mapper : 为了使接口被其他类引用,需要使用@Mapper注解,这种方式要求每一个mapper类都需要添加此注解,麻烦. package com.example.demo.dao; imp ...

  9. ajax提交转码解码

    js 文字传输加密 encodeURI(encodeURI(distName)) java 解密 URLDecoder.decode(request.getParameter("distNa ...

  10. 【Oracle】使用bbed恢复delete的数据

    表中的数据被delete之后并不会真正删除数据,而是打了一个删除标记,仅仅要还没有被覆盖就能够恢复回来. 实验步骤例如以下: SYS@ORCL>create table bbed_test(x  ...