用Python編寫的貝葉斯反垃圾郵件分類:antispam
antispam是用Python編寫的貝葉斯反垃圾郵件分類。
PyPI: pypi.python.org/pypi/antispam Docs: antispam.readthedocs.org
Installation
pip install antispam
Usage
Use the built-in model provided & trained by author:
import antispam
antispam.score("Cheap shoes for sale at DSW shoe store!")
# => 0.9657724517163143
antispam.is_spam("Cheap shoes for sale at DSW shoe store!")
# => True
antispam.score("Hi mark could you please send me a copy of your machine learning homework? thanks")
# => 0.0008064840568731558
antispam.is_spam("Hi mark could you please send me a copy of your machine learning homework? thanks")
# => FalseTrain your own modle:
import antispam
d = antispam.Detector("my_model.dat")
d.train("Super cheap octocats for sale at GitHub.", True)
d.train("Hi John, could you please come to my office by 3pm? Ding", False)
msg1 = "Cheap shoes for sale at DSW shoe store!"
d.score(msg1)
# => 0.9999947825633266
d.is_spam(msg1)
# => True
msg2 = "Hi mark could you please send me a copy of your machine learning homework? thanks"
d.score(msg2)
# => 4.021280114849398e-08
d.is_spam(msg2)
# => FalseSave your model:
d.save()
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!