用户:四九圣尊查看:0 回复:28 评论:0 创建时间:2017-12-31T21:18:36
我要很详细的,谢谢!那些数学公式不要担心我不理解,我能背下来。我要很详细的教程,谢谢!
如果概念已经get了的话可以试试一下叫sklearn的python包,可以通过
pip install -U scikit-learn
来安装,里面包含有朴素贝叶斯的实现,下面是例子:
http://scikit-learn.org/stable/modules/naive_bayes.html
如果还想看具体的实现,可以看:
https:/喵scikit-learn/scikit-learn/blob/a24c8b46/sklearn/naive_bayes.py#L160
还有什么问题我们也可以继续讨论
点赞0
评论
下面是几个公开的垃圾邮件数据库:
http://c喵ining.org/index.php/spam-assassin-datasets.html
http://c喵ining.org/index.php/ling-spam-datasets.html
https://plg.uwaterloo.ca/~gvcormac/treccorpus/
http://nlp.cs.aueb.gr/software_and_datasets/Enron-Spam/index.html
如果想自己找的话,可以试试在搜索引擎上输入spam classification dataset这样的关键词来找。
点赞0
评论
import nltk import os from nltk.book import * import numpy from nltk import * from sklearn import * import easygui from nltk.corpus import stopwords english_stopwords = stopwords.words('english') xianyan = 0.5 ku = [] pass133 = os.getcwd() + "\\R" pass134 = os.getcwd() + "\\H" a = os.listdir(pass133) aa = os.listdir(pass134) txt_place= "" txt_text = "" htxt_place = "" htxt_text = "" print("开始学习!") for i in range(len(a)): ku_fu = [] txt_place = os.getcwd() + "\R" + "\\" + a[i] print(txt_place) txt_text = open(txt_place).read() txt_text = txt_text.lower() ku_fu = word_tokenize(txt_text) ku.extend(ku_fu) hku = [] for i in range(len(aa)): hku_fu = [] htxt_place =os.getcwd() + "\H" + "\\" + aa[i] print(htxt_place) htxt_text = open(htxt_place).read() htxt_text = htxt_text.lower() hku_fu = word_tokenize(htxt_text) hku.extend(hku_fu) print(hku) number = ["second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth"] ku_he = ku ciping = [] zuizhong = [] ku = [w for w in ku if w not in english_stopwords and len(w) >= 5 and w.isalpha() and w not in number] hku = [w for w in hku if w not in english_stopwords and len(w) >= 5 and w.isalpha() and w not in number] print(hku) fdist1 = FreqDist(ku) print(fdist1) zuizhong_fu = list(fdist1) print("INIT SUCCESS") for i in zuizhong_fu: zuizhong.append(i) if fdist1[i]/len(a) >= 1: ciping.append(1) elif fdist1[i]/len(a) < 1: ciping.append(float(fdist1[i]/len(a))) pass10 = input("词汇矩阵构建完成!点击enter开始测试垃圾邮件!") txt = easygui.fileopenbox(default='*.txt') text = open(txt).read() text = text.lower() text_fen = word_tokenize(text) text_fen = list(set(text_fen)) wenti = [] gongyou = [] for i in range(len(text_fen)): if text_fen[i] in zuizhong: gongyou.append(text_fen[i]) hwenti = [] for i in range(len(gongyou)): pass90 = hku.count(gongyou[i]) hwenti.append(pass90) for i in range(len(gongyou)): hwenti[i] = hwenti[i]/len(hku)*100 for i in range(len(gongyou)): wula = zuizhong.index(gongyou[i]) print("抽取:" + str(wula)) wenti.append(float(ciping[wula]*100)) zuihouha = []
就剩最后那个公式了,大佬帮帮我吧!
点赞0
评论
第一道式子里面,P(S | W)指包含了sex这个词的邮件是垃圾邮件的概率,P(W|S)和P(S)的含义前文已经解释了,把他们乘起来得到的是一封邮件既包含了sex这个词同时又是垃圾邮件的概率,P(W)是一封邮件包含sex这个词的概率
点赞0
评论