https://github.com/rcode879/gdp-life-expectancy-predictor
https://github.com/rcode879/gdp-life-expectancy-predictor
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/rcode879/gdp-life-expectancy-predictor
- Owner: Rcode879
- Created: 2025-02-10T22:08:18.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-02-10T22:19:23.000Z (3 months ago)
- Last Synced: 2025-02-10T23:23:44.468Z (3 months ago)
- Language: Jupyter Notebook
- Size: 773 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GDP-Life-expectancy-predictor
# Life Expectancy vs GDP Prediction Model## 📌 Overview
This project analyzes the relationship between **GDP per Capita** and **Life Expectancy** using **Polynomial Regression**. The model fits a **7th-degree polynomial** to predict life expectancy based on GDP per capita. The project includes:
- Data preprocessing (cleaning and transformation)
- Polynomial regression model training
- Data visualization using Matplotlib
- Interactive **console-based predictions**
- **R² error evaluation** to measure model accuracy## 🚀 Features
✅ Reads data from a CSV file
✅ Cleans and preprocesses the dataset
✅ Applies **log transformation** to GDP for better model fit
✅ Fits a **7th-degree polynomial regression model**
✅ Plots **actual vs predicted values** with a logarithmic scale
✅ Allows **user input to predict life expectancy**
✅ Displays **R² score** to assess model accuracy
✅ Interactive **menu for user interaction**---
## 🛠️ Installation & Setup
### **1️⃣ Clone the Repository**
```sh
git clone https://github.com/Rcode879/GDP-Life-expectancy-predictor.git
cd GDP-Life-expectancy-predictor
```### **2️⃣ Install Dependencies**
Ensure you have Python installed. Then, install the required libraries:
```sh
pip install numpy pandas matplotlib scikit-learn
```### **3️⃣ Run the Script**
```sh
python main.py
```---
## 📊 How It Works
1. **Load & Clean Data**
- Reads the dataset from `life-expectancy-vs-gdp-per-capita.csv`
- Drops unnecessary columns and handles missing values2. **Apply Log Transformation**
- GDP is **log-transformed** to make the relationship more linear
3. **Train Polynomial Regression Model**
- Fits a **7th-degree polynomial** using `np.polyfit()`
4. **Plot the Model**
- Scatter plot of GDP vs. Life Expectancy
- Polynomial regression curve (red line) overlayed
- **Logarithmic x-axis** for better visualization5. **Interactive Console Menu**
- `p` → Predict life expectancy for a user-input GDP value
- `t` → Display the **R² error** of the model
- `g` → Show the **graph** of the model
- `q` → Quit the program---
## 📈 Example Usage
```
Enter 'p' to make a prediction, 't' to view R² error, 'g' to view graph, 'q' to quit: p
Enter the GDP per Capita: 65020.35
The estimated life expectancy of a country with 65020.35 GDP per capita is 77.7771393826115 years
```## NOTE:
- There is also a notebook which provides a visual explaination of the code