Welcome to the Harry Potter Sorting Hat project! This machine learning-based web application classifies users into one of the four Hogwarts Houses based on their personality traits derived from the Big Five Personality Score.
Hogwarts was founded over a thousand years ago by four powerful wizards: Godric Gryffindor, Salazar Slytherin, Rowena Ravenclaw, and Helga Hufflepuff. They chose to split the students into four ‘houses’, each bearing their surnames and featuring young wizards and witches who displayed abilities and personalities they wanted to nurture.
To do this, Godric Gryffindor used his magical hat – henceforward known as the Sorting Hat – to decide which children should go into which house, and so it has been ever since with a yearly Sorting Ceremony that places each new pupil into their own new home.
The four houses have different entry requirements, and nobody summed them up better than the old Sorting Hat itself in its welcoming song:
‘You might belong in Gryffindor,
Where dwell the brave at heart,
Their daring, nerve and chivalry
Set Gryffindors apart.’
‘You might belong in Hufflepuff
Where they are just and loyal
Those patient Hufflepuffs are true
And unafraid of toil.’
‘Or yet in wise old Ravenclaw
If you’ve a ready mind
Where those of wit and learning
Will always find their kind.’
‘Or perhaps in Slytherin
You’ll make your real friends
Those cunning folk use any means
To achieve their ends.’
- Overview
- Features
- Tech Stack
- Installation
- Usage
- Dataset
- Results
- Model Details
- Screenshots and Video
- Contributing
- License
- Contact
This project uses a machine learning model to predict a user’s Hogwarts House: Gryffindor, Hufflepuff, Ravenclaw, or Slytherin. The classification is based on the Big Five Personality Score, which measures personality traits such as openness, conscientiousness, extraversion, agreeableness, and neuroticism.
- Interactive web application to predict Hogwarts House
- Dynamic UI for personality trait input
- Integration of a trained ML model with Flask backend
- Accurate predictions with 81.34% accuracy on test data
- HTML
- CSS
- JavaScript
- Bootstrap
- Python
- Flask
- scikit-learn
- pandas
- numpy
Follow these steps to set up the project locally:
-
Clone the repository:
git clone https://github.com/Angad-2002/Harry-Potter-Sorting-Hat.git cd Harry-Potter-Sorting-Hat -
Create a virtual environment and activate it:
python -m venv venv # For Windows: venv\Scripts\activate # For macOS/Linux: source venv/bin/activate
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the Flask application:
python app.py
-
Open your browser and go to:
http://127.0.0.1:5000/
- Input your Big Five Personality traits into the form on the web application.
- Submit the form to get your Hogwarts House prediction.
- View your house along with a brief description of its qualities.
The project uses a preprocessed dataset containing individuals’ Big Five Personality Scores and their associated Hogwarts Houses. The dataset was cleaned and split into training and testing sets for model evaluation.
The dataset was created based on the personality traits visualized in the following box chart:
The chart represents the distribution of traits such as Agreeableness, Conscientiousness, Emotional Stability, Extraversion, and Intellect for individuals grouped by their Hogwarts Houses.
- Model Accuracy: 81.34% on the test dataset.
- Classifier: Trained using scikit-learn's machine learning algorithms.
The project employs the Gaussian Naive Bayes Classifier to classify individuals into Hogwarts Houses. Key highlights of the model:
-
Algorithm: Gaussian Naive Bayes
- Assumes that features follow a Gaussian (Normal) distribution.
- Suitable for continuous input features like personality trait scores.
- Simple and computationally efficient.
-
Why Gaussian Naive Bayes?
- Works well with smaller datasets.
- Handles continuous data effectively by modeling feature likelihoods with Gaussian distribution.
- Provides fast predictions, ideal for a real-time application like this.
Watch the application in action:
Click the thumbnail to watch the video on YouTube.
Contributions are welcome! If you have suggestions or improvements, feel free to:
- Fork the repository.
- Create a new branch:
git checkout -b feature-name
- Commit your changes:
git commit -m 'Add some feature' - Push to the branch:
git push origin feature-name
- Open a Pull Request.
This project is licensed under the MIT License.
For any inquiries, feel free to reach out:
- Author: Angad Singh
- Email: [email protected]
- GitHub: Angad-2002









