Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

35 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‘₯ MBTI Text Classifier

GitHub repo size Python GitHub License Jupyter scikit-learn

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.

πŸ“‹ Overview

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

🎯 MBTI Types

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

πŸ“ Project Structure

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

πŸš€ Getting Started

Prerequisites

  • Python 3.11+
  • pip

Installation

  1. Clone the repository:

    git clone https://github.com/Mr-MRF-Dev/MBTI-Text-Classifier.git
    cd MBTI-Text-Classifier
  2. Create and activate virtual environment:

    python -m venv venv
    
    # Windows
    .\venv\Scripts\activate
    
    # Linux/Mac
    source venv/bin/activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. (Optional) Install pre-commit hooks:

    pre-commit install
  5. Run the notebook:

    jupyter notebook notebook.ipynb

    or using JupyterLab:

     jupyter lab notebook.ipynb

πŸ€– Models

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

πŸ“Š Results

The SVM model achieves the best performance:

  • βœ… Accuracy: ~90%
  • βœ… F1-Score: ~0.90
  • βœ… Best dimension: S/N (~98%)
  • ⚠️ Hardest dimension: J/P (~94%)

πŸ“ˆ Visualizations

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)

πŸ› οΈ Tech Stack

Category Technologies
Language Python
Data Pandas, NumPy
ML Scikit-learn, imbalanced-learn
NLP NLTK, TF-IDF
Visualization Matplotlib, Seaborn
Dataset KaggleHub

πŸ”§ Pre-commit Hooks

This project uses pre-commit for code quality:

  • black - Code formatting
  • isort - Import sorting
  • flake8 - Linting
  • nbqa - Notebook code quality

πŸ™ Acknowledgments

🀝 Contributing

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.

πŸ“ License

This project is licensed under the MIT License. For more information, please refer to the LICENSE file.

About

πŸ‘₯ A machine learning project that classifies text into one of the 16 MBTI personality types based on user posts.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Used by

Contributors

Languages