Personality Prediction ML Model Development

Jainish

Jainish Prajapati

Personality Prediction ML

A machine learning model that predicts personality types (Introvert/Extrovert) using behavioral patterns and Random Forest classification with Flask REST API implementation.

Overview

This project uses machine learning to analyze behavioral patterns and predict whether someone is more likely to be an introvert or extrovert. It leverages a Random Forest Classifier trained on various behavioral indicators and provides predictions through a REST API.

Features

Predicts personality type based on 7 behavioral indicators
Random Forest Classifier with optimized performance
REST API implementation using Flask
Comprehensive data visualization and analysis
Data preprocessing and feature scaling
Model persistence using pickle

Tech Stack

Python 3.x
scikit-learn
Flask
pandas
numpy
matplotlib
seaborn

Project Structure

personality-prediction-ml/

├── models/ # Saved model files
│ ├── random_forest_model.pkl
│ ├── logistic_regression_model.pkl
│ ├── svm_model.pkl
│ └── scaler.pkl

├── main.ipynb # Main analysis notebook
├── api.py # Flask API implementation
├── personality_dataset.csv # Dataset
├── requirements.txt # Project dependencies
└── README.md

API Endpoints

POST /predict

Predicts personality type based on behavioral inputs.
Request Body:
{
"time_spent_alone": 7.0, # Range: 0-10
"stage_fear": "Yes", # Options: "Yes"/"No"
"social_event_attendance": 2.0, # Range: 0-10
"going_outside": 3.0, # Range: 0-7
"drained_after_socializing": "Yes", # Options: "Yes"/"No"
"friends_circle_size": 4.0, # Range: 0-15
"post_frequency": 2.0 # Range: 0-10
}
Response:
{
"personality": "Introvert", # or "Extrovert"
"success": true
}

Setup Guide

Create virtual environment:
python -m venv .venv
source .venv/bin/activate # Linux/Mac
Install dependencies:
pip install -r requirements.txt

Dependencies

Create requirements.txt with:
flask==3.0.0
numpy==1.24.3
pandas==2.1.1
scikit-learn==1.3.0
matplotlib==3.8.0
seaborn==0.13.0

Model Details

Algorithm: Random Forest Classifier
Features: 7 behavioral indicators
Preprocessing: StandardScaler for feature scaling
Performance: Evaluated using accuracy and classification report
Persistence: Models saved using pickle format

Data Analysis

The project includes comprehensive data analysis in main.ipynb:
Feature importance visualization
Correlation analysis
Distribution plots
Personality type distributions
Model performance comparisons

API Implementation

The Flask API (api.py) provides:
RESTful endpoint for predictions
Input validation
Error handling
Model loading and preprocessing
JSON response formatting

Environment

Python 3.x
Linux/Unix environment
Required packages listed in requirements.txt
Like this project

Posted Jun 24, 2025

Developed a personality prediction ML model using Random Forest and Flask API.