Skip to content

About

social media comment sentiment analysis

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Sentiment Analysis

Status: Prototype Python

A small, friendly sentiment analysis demo in Python. This repository contains a compact end-to-end example that:

  • Preprocesses text (cleaning, stopwords, stemming)
  • Vectorizes text with TF-IDF
  • Trains a simple classifier (Multinomial Naive Bayes / Logistic Regression)
  • Evaluates and visualizes results (confusion matrix + accuracy chart)

This project is perfect as a quick demo, teaching aid, or starting point for experimentation and model improvements.


Highlights

  • Minimal, easy-to-read code in sentiment_analysis.py.
  • Small synthetic dataset included for quick experimentation.
  • Produces a visualization file: sentiment_analysis_results.png.
  • Works inside a virtual environment (env/) — examples in this README assume PowerShell on Windows.

Quick demo (PowerShell)

Open PowerShell in the project folder and run the script using the bundled venv Python:

# Activate the venv (if not already active)
& .\env\Scripts\Activate.ps1

# Run the demo script
& .\env\Scripts\python.exe .\sentiment_analysis.py

Expected outcome: the script will preprocess the sample data, train a model, print evaluation metrics, save sentiment_analysis_results.png, and display example predictions.


Installation (recommended)

If you prefer to recreate the environment or run with your own Python setup:

# Create a venv
python -m venv .venv

# Activate it
& .\.venv\Scripts\Activate.ps1

# Install dependencies
pip install -r requirements.txt

Note: This repository already includes a working env/ virtual environment. If you use it, you do not need to reinstall the packages.

If you want a quick requirements.txt, you can generate one from the venv with:

# from within the venv
pip freeze > requirements.txt

Usage

  • Edit sentiment_analysis.py to change the sample dataset, tweak preprocessing, or swap model types (naive_bayes or logistic_regression).
  • The script saves a plot to sentiment_analysis_results.png. Use that image for visual inspection or documentation.
  • Example: Change the test_texts list near the bottom of the file to try different inputs.

File map

  • sentiment_analysis.py — main script (preprocessing, vectorization, training, evaluation, plotting)
  • sentiment_analysis_results.png — output plot (generated by running the script)
  • env/ — included virtual environment (Windows)

Model & Data Notes

  • Vectorization: TfidfVectorizer(max_features=5000)
  • Models included: MultinomialNB (default) and LogisticRegression (option)
  • Preprocessing: lowercasing, URL/mention/hashtag removal, non-alpha stripping, stopword removal, Porter stemming

Caveats:

  • The toy dataset is small and synthetic — results are for demonstration only.
  • Evaluation metrics may show warnings for classes with extremely few or no predictions.

Next improvements (ideas)

  • Replace stemming with lemmatization (NLTK/WordNet or spaCy) for better canonical forms.
  • Expand dataset and balance classes to improve evaluation reliability.
  • Try word embeddings (Word2Vec, GloVe) or transformer embeddings (e.g., from Hugging Face) for better performance.
  • Add unit tests for preprocessing and model training.

Contributing

Contributions welcome! Open an issue or PR with a descriptive title and short summary of your change. Small, focused PRs are easiest to review.

If you add a new dependency, please update requirements.txt.


License

This project is provided as-is for demo and educational purposes. Add a license file (e.g., LICENSE) to formalize terms if you plan to publish or distribute.


Made with care � — happy experimenting!

About

social media comment sentiment analysis

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages