| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [View Raw Code] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
This project demonstrates a basic text classification algorithm using Python and common NLP libraries. The goal is to classify text into different categories, specifically positive and negative sentiments.
text_classification/ ├── data/ │ └── text_data.csv ├── models/ │ └── text_classifier.pkl ├── preprocess.py ├── train.py └── classify.py
The dataset (text_data.csv) contains 200 entries with two columns: text and label. The text column contains the text to be classified, and the label column contains the corresponding category (positive or negative).
The preprocess.py file contains functions to preprocess the text data. It includes removing non-alphabetic characters, converting text to lowercase, removing stopwords, and lemmatizing the words.
The train.py script is used to train the text classification model. It performs the following steps:
To train the model, run:
python train.pyThe classify.py script is used to classify new text using the trained model. It performs the following steps:
To classify new text, run:
python classify.pyThe project requires the following Python libraries:
You can install the dependencies using:
pip install pandas scikit-learn nltk joblib# Example usage of the classify.py script
if __name__ == "__main__":
new_text = "I enjoy working on machine learning projects."
print(f'Text: "{new_text}"')
print(f'Predicted Class: {classify_text(new_text)}')This project provides a simple text classification model using Naive Bayes with TF-IDF vectorization. You can expand it by using more advanced models or preprocessing techniques based on your requirements.
| Back | FazBrowse Home | New Git URL |