npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bayes-ch

v1.0.2

Published

朴素贝叶斯算法

Downloads

6

Readme

bayes-ch

朴素贝叶斯分类

安装

npm i bayes-ch
// or
yarn add bayes-ch

使用

导入代码

// 导入代码
const Bayes = require('bayes-ch');
// 实例化类
langBayes = new Bayes();




创建数据样本

//训练数据
langBayes.train("学校有多少个校区?分别在哪?", '校区');
langBayes.train("诚信分怎么获取", '诚信分');
langBayes.train("Ein Bayes-Klassifikator (Aussprache: [beɪz], benannt nach dem englischen Mathematiker Thomas Bayes), ist ein aus dem Satz von Bayes hergeleiteter Klassifikator. Er ordnet jedes Objekt der Klasse zu, zu der es mit der größten Wahrscheinlichkeit gehört, oder bei der durch die Einordnung die wenigsten Kosten entstehen. Genau genommen handelt es sich um eine mathematische Funktion, die jedem Punkt eines Merkmalsraums eine Klasse zuordnet.", 'German');
langBayes.train("Naiwny klasyfikator bayesowski – prosty klasyfikator probabilistyczny. Naiwne klasyfikatory bayesowskie są oparte na założeniu o wzajemnej niezależności predyktorów (zmiennych niezależnych). Często nie mają one żadnego związku z rzeczywistością i właśnie z tego powodu nazywa się je naiwnymi. Bardziej opisowe jest określenie – „model cech niezależnych”. Ponadto model prawdopodobieństwa można wyprowadzić korzystając z twierdzenia Bayesa.", 'Polish');

调用数据

//获取每个分类的匹配度
var scores = langBayes.guess('诚信分');
console.log(scores);
//获取最高匹配度的对象
var winner = langBayes.extractWinner(scores);
console.log(winner);

查询结果

{
  '校区': 0.4,
  '诚信分': 0.8571428571428571,
  German: 0.06250000000000003,
  Polish: 0.06250000000000003
}
{ label: '诚信分', score: 0.8571428571428571 }

导出json模型

let jsonData = langBayes.toJSON();
fs.writeFileSync("train.json",jsonData);

使用json模型

var Bayes = require('../bayes');
langBayes = new Bayes();
// 导入数据
const   json = require('./train.json');
// json转换成功实例
langBayes.fromJSON(JSON.stringify(json))
// 推测数据
var scores = langBayes.guess('诚信分');
console.log(scores);
// 提取匹配度最高的数据
var winner = langBayes.extractWinner(scores);
console.log(winner);