A machine learning project that classifies text into one of the 16 MBTI personality types based on user posts. This project uses classic ML techniques with TF-IDF feature extraction to analyze text and predict personality types.
This project implements a complete ML pipeline for MBTI personality classification:
- π₯ Downloads and preprocesses the MBTI dataset from Kaggle
- π§Ή Performs text cleaning and TF-IDF feature extraction
- βοΈ Handles class imbalance using Random Oversampling
- π€ Trains and evaluates three classic ML models
- π Provides detailed error analysis and visualizations
The Myers-Briggs Type Indicator consists of 16 personality types based on four dimensions:
| Dimension | Description |
|---|---|
| E/I | Extraversion vs Introversion |
| S/N | Sensing vs Intuition |
| T/F | Thinking vs Feeling |
| J/P | Judging vs Perceiving |
MBTI-Text-Classifier/
βββ notebook.ipynb # Main Jupyter notebook
βββ requirements.txt # Python dependencies
βββ .pre-commit-config.yaml # Pre-commit hooks
βββ .gitignore
βββ LICENSE
βββ README.md
βββ docs/
β βββ REPORT_FA.md # Project report in Persian
β βββ REPORT_EN.md # Project report in English
βββ data/
β βββ raw_data.csv # Original dataset
β βββ processed_data.csv # Cleaned dataset
βββ models/
β βββ svm_model.pkl # Trained best model
β βββ tfidf_vectorizer.pkl # TF-IDF vectorizer
βββ images/ # Generated visualizations
βββ 01_mbti_distribution.png
βββ 02_original_class_distribution.png
βββ 03_resampled_class_distribution.png
βββ 04_model_performance_comparison.png
βββ 05_confusion_matrices.png
βββ 06_per_type_accuracy.png
βββ 07_dimension_accuracy.png
- Python 3.11+
- pip
-
Clone the repository:
git clone https://github.com/Mr-MRF-Dev/MBTI-Text-Classifier.git cd MBTI-Text-Classifier -
Create and activate virtual environment:
python -m venv venv # Windows .\venv\Scripts\activate # Linux/Mac source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
(Optional) Install pre-commit hooks:
pre-commit install
-
Run the notebook:
jupyter notebook notebook.ipynb
or using JupyterLab:
jupyter lab notebook.ipynb
Three classic ML models are trained and compared:
| Model | Accuracy | F1-Score |
|---|---|---|
| SVM | ~90% | ~0.90 |
| Logistic Regression | ~88% | ~0.87 |
| Naive Bayes | ~78% | ~0.78 |
The SVM model achieves the best performance:
- β Accuracy: ~90%
- β F1-Score: ~0.90
- β Best dimension: S/N (~98%)
β οΈ Hardest dimension: J/P (~94%)
The notebook generates various visualizations saved in the images/ folder:
- MBTI type distribution
- Class distribution (before/after oversampling)
- Model performance comparison
- Confusion matrices for all models
- Per-type classification accuracy
- Dimension-level accuracy (E/I, S/N, T/F, J/P)
| Category | Technologies |
|---|---|
| Language | Python |
| Data | Pandas, NumPy |
| ML | Scikit-learn, imbalanced-learn |
| NLP | NLTK, TF-IDF |
| Visualization | Matplotlib, Seaborn |
| Dataset | KaggleHub |
This project uses pre-commit for code quality:
- black - Code formatting
- isort - Import sorting
- flake8 - Linting
- nbqa - Notebook code quality
- Dataset: MBTI Dataset on Kaggle
We welcome any contributions you may have. If you're interested in helping out, please fork the repository and create an Issue or Pull Request. We'll be happy to review your contributions.
This project is licensed under the MIT License. For more information, please refer to the LICENSE file.