A Flask based webserver which accepts text from user through webservice, and generates prediction whether the text is spam or ham.
The data is a collection of SMS messages tagged as spam or ham that can be found here. First, we will use this dataset to build a prediction model that will accurately classify which texts are spam.
Naive Bayes classifiers are a popular statistical technique of e-mail filtering. They typically use bag of words features to identify spam e-mail. Therefore, We’ll build a simple message classifier using Naive Bayes theorem.
Run the following command on the root dorectory of this project.
Optional commands to create virual environment to install dependency:
Create virtual environment: 'python -m venv spamclassifier'
Activate virual environment: 'spamclassifier\Scripts\activate'
Command to start server:
install dependency: 'pip install -r requirements.txt'
flask run
This will start flask based spam classifier server in production mode.
To access home page browse to http://localhost:5000
To start python notebook from within python virtual environment follow below commands:
ipython kernel install --user --name=spamclassifier
jupyter notebook
- open
DataModelling&NaiveBayesModel.ipynb
from browser.
NOTE: if you are running multiple kernels in jupyter notebook, switch to spamclassifier
kernel from kernel->change kernel->spamclassifier
from browser.
localhost:5000\train
will load dataset and create vocabulary, train Naive Bayes model using it.localhost:5000\
orlocalhost:5000\index
is the main page of the web app.localhost:5000\predict
will predict the class of text passed. This api will load trained model which were created from 1st url and use it for prediction.