spammy:为您服务的垃圾邮件过滤
项目描述
<图>
</图>
</图>
- 作者:
- 最新版本:
1.0.3
内容
</nav>1概述
spammy : 为您服务的垃圾邮件过滤
2特点
3示例
>>> import os
>>> from spammy import Spammy
>>>
>>> directory = '/home/tasdik/Dropbox/projects/spamfilter/data/corpus3'
>>>
>>> # directory structure
>>> os.listdir(directory)
['spam', 'Summary.txt', 'ham']
>>> os.listdir(os.path.join(directory, 'spam'))[:5]
['4257.2005-04-06.BG.spam.txt', '0724.2004-09-21.BG.spam.txt', '2835.2005-01-19.BG.spam.txt', '2505.2005-01-03.BG.spam.txt', '3992.2005-03-19.BG.spam.txt']
>>>
>>> # Spammy object created
>>> cl = Spammy(directory, limit=100)
>>> cl.train()
>>>
>>> SPAM_TEXT = \
... """
... My Dear Friend,
...
... How are you and your family? I hope you all are fine.
...
... My dear I know that this mail will come to you as a surprise, but it's for my
... urgent need for a foreign partner that made me to contact you for your sincere
... genuine assistance My name is Mr.Herman Hirdiramani, I am a banker by
... profession currently holding the post of Director Auditing Department in
... the Islamic Development Bank(IsDB)here in Ouagadougou, Burkina Faso.
...
... I got your email information through the Burkina's Chamber of Commerce
... and industry on foreign business relations here in Ouagadougou Burkina Faso
... I haven'disclose this deal to any body I hope that you will not expose or
... betray this trust and confident that I am about to repose on you for the
... mutual benefit of our both families.
...
... I need your urgent assistance in transferring the sum of Eight Million,
... Four Hundred and Fifty Thousand United States Dollars ($8,450,000:00) into
... your account within 14 working banking days This money has been dormant for
... years in our bank without claim due to the owner of this fund died along with
... his entire family and his supposed next of kin in an underground train crash
... since years ago. For your further informations please visit
... (http://news.bbc.co.uk/2/hi/5141542.stm)
... """
>>> cl.classify(SPAM_TEXT)
'spam'
>>>
分类器的准确性
>>> from spammy import Spammy
>>> directory = '/home/tasdik/Dropbox/projects/spammy/examples/training_dataset'
>>> cl = Spammy(directory, limit=300) # training on only 300 spam and ham files
>>> cl.train()
>>> cl.accuracy(directory='/home/tasdik/Dropbox/projects/spammy/examples/test_dataset', label='spam', limit=300)
0.9554794520547946
>>> cl.accuracy(directory='/home/tasdik/Dropbox/projects/spammy/examples/test_dataset', label='ham', limit=300)
0.9033333333333333
>>>
注意:可以在示例目录中找到更多示例
4安装
<图>注意:目前仅支持python2
先安装依赖
$ pip install nltk==3.2.1, beautifulsoup4==4.4.1
要安装使用 pip:
$ pip install spammy
或使用 easy_install
$ easy_install spammy
或者自己构建它(仅在必须时):
$ git clone https://github.com/prodicus/spammy.git
$ python setup.py install
4.1升级
要升级软件包,
$ pip install -U spammy
4.2代理后安装
如果您在代理后面,那么这应该可以
$ pip --proxy [username:password@]domain_name:port install spammy
5基准
训练后垃圾邮件的速度非常快
不相信我?看一看
>>> import timeit
>>> from spammy import Spammy
>>>
>>> directory = '/home/tasdik/Dropbox/projects/spamfilter/data/corpus3'
>>> cl = Spammy(directory, limit=100)
>>> cl.train()
>>> SPAM_TEXT_2 = \
... """
... INTERNATIONAL MONETARY FUND (IMF)
... DEPT: WORLD DEBT RECONCILIATION AGENCIES.
... ADVISE: YOUR OUTSTANDING PAYMENT NOTIFICATION
...
... Attention
... A power of attorney was forwarded to our office this morning by two gentle men,
... one of them is an American national and he is MR DAVID DEANE by name while the
... other person is MR... JACK MORGAN by name a CANADIAN national.
... This gentleman claimed to be your representative, and this power of attorney
... stated that you are dead; they brought an account to replace your information
... in other to claim your fund of (US$9.7M) which is now lying DORMANT and UNCLAIMED,
... below is the new account they have submitted:
... BANK.-HSBC CANADA
... Vancouver, CANADA
... ACCOUNT NO. 2984-0008-66
...
... Be further informed that this power of attorney also stated that you suffered.
... """
>>>
>>> def classify_timeit():
... result = cl.classify(SPAM_TEXT_2)
...
>>> timeit.repeat(classify_timeit, number=5)
[0.1810469627380371, 0.16121697425842285, 0.16121196746826172]
>>>
6贡献
有关详细信息,请参阅贡献页面
6.1路线图
包括更多算法以提高准确性
python3 支持
7许可
Spammy 由Tasdik Rahman构建,并在 GPLv3 下获得许可。
垃圾邮件版权所有 (C) 2016 Tasdik Rahman ( prodicus@outlook.com )
本程序是免费软件:您可以根据自由软件基金会发布的 GNU 通用公共许可证条款重新分发和/或修改它,许可证的第 3 版或(由您选择)任何更高版本。
分发此程序的目的是希望它有用,但不提供任何保证;甚至没有对适销性或特定用途适用性的默示保证。有关详细信息,请参阅 GNU 通用公共许可证。
您应该已经收到了一份 GNU 通用公共许可证的副本以及该程序。如果没有,请参阅 < http://www.gnu.org/licenses/ >。
您可以在此处找到 LICENSE 文件的完整副本
8学分
如果你想在你博客的某个地方给我点赞,或者在推特上向@tasdikrahman大喊一声,好吧,我会接受的。