zoukankan      html  css  js  c++  java
  • [Javascript] Classify text into categories with machine learning in Natural

    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("
    ");
        console.log(item.text);
        console.log("Label:", labelGuess);
        console.log(classifier.getClassifications(item.text));
    });
  • 相关阅读:
    内网横向渗透之票据传递攻击
    内网横向渗透之哈希传递攻击
    冰蝎2,3及哥斯拉特征分析
    钓鱼攻击之远程加载恶意Word模版文件上线CS
    powershell基础知识
    初学文件钓鱼
    powershell免杀
    tips
    ShardingSphere你还不会吗?(第一篇)
    Ubunt14.04+Nvidia drivers+cuda 8.0
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7624277.html
Copyright © 2011-2022 走看看