Naive Bayes Classifier - with sample of classifying spam/ham mails

  1. Bayes’ theorem

Wiki Page : https://en.wikipedia.org/wiki/Bayes'_theorem

P(A|B) = P(B|A) = P(B|A) P(A)/P(B)

  1. Naive Bayes Classifier

Wiki Page : https://en.wikipedia.org/wiki/Naive_Bayes_classifier

  1. Use naive bayes classifier to resolve a sample problem
    3.1 the problem we need to resolve
    We have below training sets:
    a. Get up to 10% pay off of on under Armour, you’ve still got time, buy not much.(Spam)
    b. Wonderful news, Cold Gear under $50. Right here, Right Now!(Spam)
    c. Please help with the development work asap, we need to catch up with the deadline(Ham)
    d. JavaScript developer, Full Stack developer, good oppotunity in Shanghai.(Ham)

With these 4 training sets, we need to classify if below mails are spam/ham mails:
a. We provide 20% pay off, buy it!
b. Re: Applying for javaScript develper…

3.2 Analysis using Naive Bayes Classifier
We need to resolve :
P(spam | mail) The Probability that given mail is spam
P(ham | mail) The Probability that given mail is ham
=>
P(spam | mail) = P(spam) * P(mail | spam) / P(mail)
P(ham | mail) = P(ham) * P(mail | ham) / P(mail)

We will just compare P(spam | mail) with P(ham | mail) to decide if the mail is spam or ham.
So we can ignore P(mail) and just compare :
P(spam) * P(mail | spam) & P(ham) * P(mail | ham)

P(spam) = No. of mails belonging to category spam
P(ham) = No. of mails belonging to category ham
in our given training set, they are both 0.5

P(mail | spam) = P(word1 | spam) * P(word2 | spam) * …
P(mail | ham) = P(word1 | ham) * P(word2 | ham) * …
P(word1 | spam) = count of word1 in all the spam mails / count of all the words in spam mails

things to note : if in the testing set we have a new word which is not in the training set, P(NewWord | spam) would be 0, then the multiply chain would also be 0. We cannot continue to calculate.
So we add log function to both side before compare.
if log(P(spam | mail)) > log (P(ham | mail)), return spam
else return ham

log(P(spam | mail)) = log(P(spam)) + log(P(mail | spam) - log(P(mail) =
log(P(ham | mail)) = log(P(ham)) + log(P(mail | ham) - log(P(mail)

We need to compare :
log(P(spam)) + log(P(word1 | spam)) + log (P(word2 | spam)) + …
log(P(ham)) + log(P(word1 | ham)) + log (P(word2 | ham)) + …

But the problem was still not resolved, if we meet new word, P(newWord | spam) would be 0 and log(0) cannot be calculated.
let’s use Laplace smoothing :
log(P(word1 | spam)) = (count of word1 in spam mails + 1) / (total count of words in spam mails + no. of distinct words in training data set)

3.3 Use C# to do the coding
a. Make the mail content(subject) as tokens, ignore the numbers and symbols, just get list of strings, also delete some stop words
在这里插入图片描述
在这里插入图片描述

b. Train the data sets, I do this all in memory, do not use database, just for experiment.
The WordFrequency is a model to save the training data
在这里插入图片描述

Sample of some saved training data :
在这里插入图片描述

c. Classify the testing data :
在这里插入图片描述
在这里插入图片描述

内容概要:本文介绍了基于Python实现的SSA-GRU(麻雀搜索算法优化门控循环单元)时间序列预测项目。项目旨在通过结合SSA的全局搜索能力和GRU的时序信息处理能力,提升时间序列预测的精度和效率。文中详细描述了项目的背景、目标、挑战及解决方案,涵盖了从数据预处理到模型训练、优化及评估的全流程。SSA用于优化GRU的超参数,如隐藏层单元数、学习率等,以解决传统方法难以捕捉复杂非线性关系的问题。项目还提供了具体的代码示例,包括GRU模型的定义、训练和验证过程,以及SSA的种群初始化、迭代更新策略和适应度评估函数。; 适合人群:具备一定编程基础,特别是对时间序列预测和深度学习有一定了解的研究人员和技术开发者。; 使用场景及目标:①提高时间序列预测的精度和效率,适用于金融市场分析、气象预报、工业设备故障诊断等领域;②解决传统方法难以捕捉复杂非线性关系的问题;③通过自动化参数优化,减少人工干预,提升模型开发效率;④增强模型在不同数据集和未知环境中的泛化能力。; 阅读建议:由于项目涉及深度学习和智能优化算法的结合,建议读者在阅读过程中结合代码示例进行实践,理解SSA和GRU的工作原理及其在时间序列预测中的具体应用。同时,关注数据预处理、模型训练和优化的每个步骤,以确保对整个流程有全面的理解。
内容概要:本文详细介绍了如何使用PyQt5创建一个功能全面的桌面备忘录应用程序,涵盖从环境准备、数据库设计、界面设计到主程序结构及高级功能实现的全过程。首先,介绍了所需安装的Python库,包括PyQt5、sqlite3等。接着,详细描述了SQLite数据库的设计,创建任务表和类别表,并插入默认类别。然后,使用Qt Designer设计UI界面,包括主窗口、任务列表、工具栏、过滤器和日历控件等。主程序结构部分,展示了如何初始化UI、加载数据库数据、显示任务列表以及连接信号与槽。任务管理功能方面,实现了添加、编辑、删除、标记完成等操作。高级功能包括类别管理、数据导入导出、优先级视觉标识、到期日提醒、状态管理和智能筛选等。最后,提供了应用启动与主函数的代码,并展望了扩展方向,如多用户支持、云同步、提醒通知等。 适合人群:零基础或初学者,对Python和桌面应用程序开发感兴趣的开发者。 使用场景及目标:①学习PyQt5的基本使用方法,包括界面设计、信号与槽机制;②掌握SQLite数据库的基本操作,如创建表、插入数据、查询等;③实现一个完整的桌面应用程序,具备增删改查和数据持久化功能;④了解如何为应用程序添加高级特性,如类别管理、数据导入导出、到期日提醒等。 阅读建议:此资源不仅适用于零基础的学习者,也适合有一定编程经验的开发者深入理解PyQt5的应用开发。建议读者跟随教程逐步实践,结合实际操作来理解和掌握每个步骤,同时可以尝试实现扩展功能,进一步提升自己的开发技能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值