A machine learning project that predicts Sri Lanka's adolescent fertility rates using 64 years of World Bank data (1960-2023). The project achieves 78% accuracy in forecasting and reveals a remarkable 78.7% decline in fertility rates over six decades.
# Clone the repository
git clone <your-repo-url>
cd fertility-forecasting-sri-lanka
# Set up environment
python3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run the analysis
python fertility_analysis_minimal.py- Best Model: Linear Regression (MAE: 3.326)
- Historical Trend: 78.7% decline from 1960 to 2023
- 2030 Prediction: 4.4 births per 1,000 women
- Policy Success: World-class fertility reduction achievement
βββ README.md # This file
βββ PROJECT_REPORT.md # Detailed analysis report
βββ requirements.txt # Python dependencies
βββ .gitignore # Git ignore rules
βββ datasets/
β βββ social-development_lka.csv # World Bank data
βββ fertility_analysis_minimal.py # Main analysis script
βββ fertility_forecasting.py # Comprehensive framework
βββ fertility_analysis_simple.py # Extended analysis with plots
βββ generated_files/
βββ PROJECT_SUMMARY.md
βββ dataset_analysis.py
βββ forecasting_project_proposal.md
Prerequisites:
- Python 3.8 or higher
- pip package manager
- 2GB free disk space
Create Virtual Environment:
# Create virtual environment
python3 -m venv venv
# Activate it
source venv/bin/activate # Linux/Mac
# OR
venv\Scripts\activate # Windows# Install required packages
pip install pandas numpy matplotlib seaborn scikit-learn
# Optional: For advanced models
pip install prophet tensorflow statsmodels plotly dashOr use requirements file:
pip install -r requirements.txtQuick Analysis (5 minutes):
python fertility_analysis_minimal.pyFull Analysis with Visualizations (15 minutes):
python fertility_analysis_simple.pyComprehensive Framework (30 minutes):
python fertility_forecasting.pyThe analysis will output:
- Model performance metrics
- Future predictions (2024-2030)
- Key insights and trends
- Generated visualizations (if applicable)
Sri Lanka Adolescent Fertility Rate Analysis
==================================================
Loading data...
Data loaded: 64 observations from 1960 to 2023
Basic Statistics:
Mean: 32.64
Std: 13.44
Range: 15.1 to 71.0
Trend Analysis:
1960: 71.0 births per 1,000 women
2023: 15.1 births per 1,000 women
Total decline: -78.7%
Forecasting Models:
Linear - MAE: 3.326, RMSE: 3.561
Quadratic - MAE: 9.522, RMSE: 9.687
Cubic - MAE: 8.340, RMSE: 9.852
Best model: Linear
Future Forecasts:
2024: 8.75
2025: 8.03
2026: 7.31
2027: 6.59
2028: 5.87
2029: 5.15
2030: 4.43
==================================================
KEY INSIGHTS
==================================================
β’ Remarkable 79% decline over 63 years
β’ Consistent downward trend
β’ Current rate among lowest in South Asia
β’ Projected 2030 rate: 4.4
β’ Policy success story in family planning
Analysis completed successfully!
- OS: Windows 10+, macOS 10.14+, or Linux
- Python: 3.8, 3.9, 3.10, or 3.11
- RAM: 4GB minimum (8GB recommended)
- Storage: 2GB free space
pandas>=1.3.0
numpy>=1.21.0
scikit-learn>=1.0.0
matplotlib>=3.4.0
seaborn>=0.11.0Optional (for advanced features):
prophet>=1.1.0
tensorflow>=2.8.0
statsmodels>=0.13.0
plotly>=5.0.0
dash>=2.0.0Source: World Bank Social Development Indicators Country: Sri Lanka (LKA) Indicator: Adolescent fertility rate (births per 1,000 women ages 15-19) Code: SP.ADO.TFRT Time Range: 1960-2023 Observations: 64 years of complete data Missing Values: None
File: datasets/social-development_lka.csv
Size: ~800KB (845 total indicators, 32 social development metrics)
Run this quick test to verify everything works:
# test_setup.py
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
print("β
All packages imported successfully!")
print(f"Python version: {python.version}")
print(f"Pandas version: {pd.__version__}")
print(f"NumPy version: {np.__version__}")
print(f"Scikit-learn version: {sklearn.__version__}")Issue 1: Module not found error
# Solution: Install missing packages
pip install <missing-package-name>Issue 2: Permission errors (Windows)
# Solution: Run as administrator or use --user flag
pip install --user <package-name>Issue 3: Python version compatibility
# Solution: Check Python version
python --version
# Upgrade if needed (Python 3.8+ required)Issue 4: Data file not found
FileNotFoundError: datasets/social-development_lka.csv
# Solution: Ensure you're in the correct directory
ls datasets/ # Should show the CSV file- Check Error Messages: Read the full error traceback
- Verify File Paths: Ensure all files are in correct locations
- Test Environment: Run the test script above
- Check Dependencies: Verify all packages are installed
- Python Version: Ensure you're using Python 3.8+
import pandas as pd
from sklearn.linear_model import LinearRegression
import numpy as np
# Load data
data = pd.read_csv("datasets/social-development_lka.csv")
fertility_data = data[data['Indicator Code'] == 'SP.ADO.TFRT'].copy()
# Prepare features
X = fertility_data['Year'].values.reshape(-1, 1)
y = fertility_data['Value'].values
# Train model
model = LinearRegression()
model.fit(X, y)
# Predict future
future_year = np.array([[2025]])
prediction = model.predict(future_year)
print(f"2025 prediction: {prediction[0]:.2f}")# Predict custom year range
start_year = 2024
end_year = 2035
future_years = np.array(range(start_year, end_year + 1)).reshape(-1, 1)
predictions = model.predict(future_years)
for year, pred in zip(range(start_year, end_year + 1), predictions):
print(f"{year}: {pred:.2f}")This project is designed for:
- Machine Learning Students: Learn regression, model evaluation, time series
- Data Science Courses: Practical application of ML to real-world data
- Public Policy Analysis: Understanding social development trends
- Research Projects: Reproducible analysis template
- Data Preprocessing: Handle real-world CSV data
- Regression Modeling: Compare different algorithms
- Model Evaluation: Use MAE, RMSE metrics appropriately
- Time Series: Understand temporal data challenges
- Business Insights: Translate technical results to actionable recommendations
Want to improve this project? Here's how:
- Fork the repository
- Create feature branch:
git checkout -b feature/your-feature - Make changes: Improve code, documentation, or analysis
- Test thoroughly: Ensure everything works
- Submit pull request: Describe your improvements
Contribution Ideas:
- Add more sophisticated models (ARIMA, Neural Networks)
- Create interactive dashboards
- Add confidence intervals
- Compare with other countries
- Improve visualizations
This project is open source and available under the MIT License.
Having issues?
- Check the troubleshooting section above
- Review error messages carefully
- Verify all requirements are met
- Test with the provided examples
For technical questions:
- Open an issue on GitHub
- Include your error message and system info
- Describe steps to reproduce the problem
- Data Source: World Bank Open Data
- Sri Lanka: Remarkable policy achievement over 60+ years
- Open Source Community: Python, scikit-learn, pandas developers
- Educational Purpose: Advancing ML education through real-world examples
Ready to explore Sri Lanka's remarkable fertility decline story through data science? Start with the Quick Start section above!