Antispam¶
Antispam is a bayesian anti-spam classifier written in Python.
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")
# => False
Documentation¶
API¶
-
antispam.
score
(msg)[source]¶ Score the message based on the built-in model.
Parameters: msg – Message to be scored in string format.
-
antispam.
is_spam
(msg)[source]¶ Decide whether the message is a spam or not based on the built-in model.
Parameters: msg – Message to be classified in string format.
antispam.Model¶
-
class
antispam.
Model
(file_path=None, create_new=False)[source]¶ Save & Load the model in/from the file system using Python’s json module.
Constructs a Model object by the indicated
file_path
, if the file does not exist, create a new file and contruct a empty model.Parameters: - file_path – (optional) Path for the model file indicated, if
path is not indicated, use the built-in model file provided by
the author, which is located in the
antispam
package folder. - create_new – (option) Boolean. If
True
, create an empty model.file_path
will be used when saving the model. If there is an existing model file on the path, the existing model file will be overwritten.
- file_path – (optional) Path for the model file indicated, if
path is not indicated, use the built-in model file provided by
the author, which is located in the
antispam.Detector¶
-
class
antispam.
Detector
(path=None, create_new=False)[source]¶ A baysian spam filter
Parameters: path – (optional) Path for the model file, will be passes to Model
and construct aModel
object based onpath
.-
train
(msg, is_spam)[source]¶ Train the model.
Parameters: - msg – Message in string format.
- is_spam – Boolean. If True, train the message as a spam, if False, train the message as a ham.
-