Update README.md
Browse files
README.md
CHANGED
|
@@ -1,3 +1,139 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
---
|
| 4 |
+
<html>
|
| 5 |
+
|
| 6 |
+
# Gender Prediction from Names using Neural Network
|
| 7 |
+
|
| 8 |
+
### π **Project Overview**
|
| 9 |
+
This project uses a **Neural Network** model trained on **TF-IDF vectors** of names to predict the gender (Male/Female). The model is deployed using **Streamlit**, making it easy to interact and predict the gender from a user-inputted name.
|
| 10 |
+
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
## πΈ **Application Screenshot**
|
| 14 |
+
<a href="https://ibb.co/7JMfmKPp"><img src="https://i.ibb.co/Y7nCshmd/Screenshot-2025-02-11-222451.png" alt="Screenshot-2025-02-11-222451" border="0" /></a>
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
## π **How It Works (End-to-End)**
|
| 18 |
+
|
| 19 |
+
### 1. **Data Preparation**
|
| 20 |
+
- The dataset `gender.xlsx` contains names and their corresponding genders (Male/Female).
|
| 21 |
+
- The `Gender` column is mapped to numerical values:
|
| 22 |
+
- **Male (M)** is mapped to `1`
|
| 23 |
+
- **Female (F)** is mapped to `0`
|
| 24 |
+
|
| 25 |
+
### 2. **Feature Extraction (TF-IDF Vectorization)**
|
| 26 |
+
- The names are converted to **TF-IDF vectors** using character n-grams (1 to 3 characters).
|
| 27 |
+
- This helps the model learn important patterns in names.
|
| 28 |
+
|
| 29 |
+
### 3. **Model Training**
|
| 30 |
+
- A **Neural Network** is built using **Keras Sequential API**:
|
| 31 |
+
- Dense layers with **ReLU activation**
|
| 32 |
+
- **Batch Normalization** and **Dropout layers** to prevent overfitting
|
| 33 |
+
- Output layer with **Sigmoid activation** for binary classification
|
| 34 |
+
- The model is trained with **callbacks** like early stopping and learning rate reduction.
|
| 35 |
+
|
| 36 |
+
### 4. **Saving the Model and Vectorizer**
|
| 37 |
+
- The trained model is saved as `gender_prediction_model_Improve.h5`
|
| 38 |
+
- The TF-IDF vectorizer is saved as `tfidf_vectorizer_Improve.joblib`
|
| 39 |
+
|
| 40 |
+
### 5. **Streamlit Application**
|
| 41 |
+
- Loads the pre-trained model and vectorizer.
|
| 42 |
+
- Accepts user input (name) and predicts gender.
|
| 43 |
+
- Displays the predicted gender in a clean UI.
|
| 44 |
+
|
| 45 |
+
---
|
| 46 |
+
|
| 47 |
+
## π **Project File Structure**
|
| 48 |
+
```
|
| 49 |
+
.
|
| 50 |
+
βββ TrainImprove.py # Training script for the model
|
| 51 |
+
βββ ml-st1.py # Streamlit app for gender prediction
|
| 52 |
+
βββ gender.xlsx # Dataset with names and gender
|
| 53 |
+
βββ gender_prediction_model_Improve.h5 # Saved Keras model
|
| 54 |
+
βββ tfidf_vectorizer_Improve.joblib # Saved TF-IDF vectorizer
|
| 55 |
+
βββ screenshot.png # Screenshot of the app UI
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
---
|
| 59 |
+
|
| 60 |
+
## π **How to Run the Project**
|
| 61 |
+
|
| 62 |
+
### 1. **Clone the Repository**
|
| 63 |
+
```bash
|
| 64 |
+
$ git clone <repository-url>
|
| 65 |
+
$ cd <repository-folder>
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
### 2. **Install Dependencies**
|
| 69 |
+
```bash
|
| 70 |
+
$ pip install -r requirements.txt
|
| 71 |
+
```
|
| 72 |
+
|
| 73 |
+
### 3. **Train the Model (Optional)**
|
| 74 |
+
If you want to retrain the model, run the training script:
|
| 75 |
+
```bash
|
| 76 |
+
$ python TrainImprove.py
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
### 4. **Run the Streamlit Application**
|
| 80 |
+
```bash
|
| 81 |
+
$ streamlit run final.py
|
| 82 |
+
```
|
| 83 |
+
|
| 84 |
+
### 5. **Access the App**
|
| 85 |
+
Open your browser and go to: [http://localhost:8501](http://localhost:8501)
|
| 86 |
+
|
| 87 |
+
---
|
| 88 |
+
|
| 89 |
+
## π‘ **How the Code Works**
|
| 90 |
+
|
| 91 |
+
### **Training (TrainImprove.py)**
|
| 92 |
+
1. **Data Loading:** Reads the dataset from `gender.xlsx`.
|
| 93 |
+
2. **Preprocessing:** Converts names to TF-IDF vectors.
|
| 94 |
+
3. **Model Building:** Defines a neural network with regularization.
|
| 95 |
+
4. **Model Training:** Trains the model with early stopping.
|
| 96 |
+
5. **Saving Artifacts:** Stores the trained model (`.h5`) and vectorizer (`.joblib`).
|
| 97 |
+
|
| 98 |
+
### **Application (final.py)**
|
| 99 |
+
1. **Load Model and Vectorizer:** Loads the pre-trained model and TF-IDF vectorizer.
|
| 100 |
+
2. **User Input:** Accepts a name input from the user.
|
| 101 |
+
3. **Prediction:** Transforms the name using TF-IDF and makes a prediction.
|
| 102 |
+
4. **Output:** Displays the predicted gender (Male/Female) in the app.
|
| 103 |
+
|
| 104 |
+
---
|
| 105 |
+
|
| 106 |
+
## π¦ **Dependencies**
|
| 107 |
+
- Python 3.x
|
| 108 |
+
- TensorFlow
|
| 109 |
+
- Scikit-learn
|
| 110 |
+
- Pandas
|
| 111 |
+
- Streamlit
|
| 112 |
+
|
| 113 |
+
Install them using:
|
| 114 |
+
```bash
|
| 115 |
+
$ pip install tensorflow scikit-learn pandas streamlit joblib
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
---
|
| 119 |
+
|
| 120 |
+
## π¨ **Future Enhancements**
|
| 121 |
+
- Improve the UI design.
|
| 122 |
+
- Include more diverse datasets for better generalization.
|
| 123 |
+
- Add confidence scores for predictions.
|
| 124 |
+
- Deploy the app online for public access.
|
| 125 |
+
|
| 126 |
+
---
|
| 127 |
+
|
| 128 |
+
## π€ **Contributing**
|
| 129 |
+
Feel free to fork the project and submit a pull request for improvements.
|
| 130 |
+
|
| 131 |
+
---
|
| 132 |
+
|
| 133 |
+
## π **License**
|
| 134 |
+
This project is licensed under the MIT License.
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
</html>
|