Coder Social home page Coder Social logo

naivebayes-spam-classifier's Introduction

NaiveBayes-Spam-Classification

Implementation Details

  1. Data Loading and Preprocessing:

    • The dataset, containing email messages labeled as 'ham' (not spam) or 'spam', is loaded from a TSV file.
    • Labels are converted into binary values (0 for 'ham' and 1 for 'spam') to facilitate training.
  2. Feature Extraction:

    • CountVectorizer is employed to transform the text messages into a matrix of token counts. This matrix serves as the feature set (X) for the machine learning model.
    • The vectorizer is first fitted on the training data (X_train) and then used to transform both training and test datasets.
  3. Model Training:

    • A Multinomial Naive Bayes model is trained on the transformed training data (X_train_transformed, y_train). This model is particularly effective for text classification problems, where the features are represented by word counts.
  4. Prediction Function:

    • The predict_spam_or_ham function takes a user input string, transforms it using the previously fitted vectorizer, and predicts whether the message is 'Spam' or 'Not Spam (ham)' using the trained Naive Bayes model.
  5. Streamlit Application:

    • The app's UI allows users to input a message and classify it as 'Spam' or 'Not Spam (ham)'.
    • The st.text_area() component captures user input, and the st.button() triggers the classification. The result is displayed using st.write().

Installation and Setup

  1. Environment Setup:

    • Ensure Python 3.7+ is installed.
    • Install required libraries:
      pip install streamlit pandas scikit-learn
  2. Running the Application:

    • Execute the Streamlit app with the following command:
      streamlit run app.py

naivebayes-spam-classifier's People

Contributors

kelvinyelyen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.