Predicting Consumer Purchase intention using Twitter Data
Predicting Consumer Purchase intention using Twitter Data
> **Final Year Project II (FYP-II)** — All material related to this project is uploaded here. The project is written primarily in Jupyter Notebook, distributed under the MIT License license, first published in 2019. Key topics include: final-year-project, ipython-notebook, machine-learning, python3, twitter-sentiment-analysis.
🛒 Predicting Consumer Purchase Intention using Twitter Data
Final Year Project II (FYP-II) — All material related to this project is uploaded here.
📖 Overview
This project leverages Twitter data and machine learning to predict whether a user has purchase intention (PI) towards a product. By analysing tweet content, we classify users as either showing purchase intention or not, and surface actionable insights through an interactive web application.
🎯 Project Details
- 🐦 Data Collection — Scrape Twitter tweets using the Twitter Search API to build a labelled dataset.
- 🏷️ Annotation — Label each tweet as PI (Purchase Intention) or No PI.
- 📊 Exploratory Data Analysis — Inspect tweet types, check for class imbalance, generate word clouds and visualisations.
- 🔧 Pre-processing — Apply text cleaning and feature-extraction techniques to build a corpus.
- 🤖 Machine Learning Models — Train and evaluate multiple classifiers:
- Support Vector Machine (SVM)
- Naive Bayes
- Logistic Regression
- Decision Tree
- Neural Network
- 📋 Output — Produce a ranked list of customers who have shown purchase intention.
- 🌐 Web Application — A Django-powered website that summarises results and lets users upload their own dataset to train/test the pre-built models.
🗂️ Repository Structure
| Folder / File | Description |
|---|---|
data/ | Annotated CSV datasets used for training and testing |
models/ | Python scripts for each ML model and pre-processing pipeline |
posters/ | Project poster and standee artwork |
SYMPOSIUM/ | Presentation slides, final report, and project completion certificate |
PurchaseIntention2.zip | Complete Django website source code |
Model Evaluation - Sheet1.pdf | Comparative model evaluation results |
⚙️ Setting Up Dependencies
Make sure you have Python (latest version) installed, then install the required packages.
📦 Install packages
bashpip3 install django numpy pandas nltk textblob scikit-learn
📥 Download TextBlob corpora
bashpython -m textblob.download_corpora
📥 Download NLTK stopwords
Open a Python terminal and run:
pythonimport nltk nltk.download('stopwords') exit()
✅ All required dependencies are now installed.
🚀 How to Run the Website
- Clone the repository and unzip
PurchaseIntention2.zip. - Open Windows Command Prompt (cmd) and navigate to the
PurchaseIntention2folder. - Activate the virtual environment:
bash
Scripts\activate - Navigate to the Django project:
bash
cd djangoPIWebsite - Start the development server:
bash
python manage.py runserver - Open your browser and go to localhost:8000 🎉
- To stop the server press Ctrl + C. To restart, re-run
python manage.py runserver.
🧪 How to Run the Model Scripts Directly
- Navigate to
CIP\PurchaseIntention2and activate the virtual environment:bashScripts\activate - Navigate to the pages directory:
bash
cd CIP\PurchaseIntention2\djangoWebsite\pages - Open a Python terminal:
bash
python - Import and run the model test module:
python
import ModelTest as mt mt.output_to_results("Annotated4.csv", "AnnotatedData2.csv", "TF-IDF", "Naive Bayes", "90", "80", "70") - 📈 The output will display prediction results and the accuracy score for the tested model.
🤝 Contributing
Contributions are welcomed and encouraged! Whether it's fixing a bug, improving the documentation, adding a new feature, or suggesting enhancements — all input is appreciated.
To contribute:
- Fork this repository.
- Create a new branch for your feature or fix:
bash
git checkout -b feature/your-feature-name - Make your changes and commit them with a clear message:
bash
git commit -m "Add: description of your change" - Push your branch to your fork:
bash
git push origin feature/your-feature-name - Open a Pull Request against the
mainbranch of this repository and describe what you've changed.
Please make sure your contributions align with the project goals and maintain code quality. For major changes, consider opening an issue first to discuss your proposal.
📜 License
This project is licensed under the terms of the LICENSE file included in this repository.
Contributors
Showing top 4 contributors by commit count.
