This deployment configuration fixes the 'SimpleImputer' object has no attribute '_fill_dtype' error caused by scikit-learn version incompatibility between training and deployment environments.
- All package versions are now explicitly pinned
- Ensures consistent environment across local and production
- Prevents automatic upgrades that break compatibility
- Models are automatically retrained during deployment
- Ensures pickle files match the deployment environment's sklearn version
- Runs only if artifacts are missing
- Uses Gunicorn instead of Flask's development server
- Better performance and reliability
- Proper timeout handling (120 seconds)
- Detailed logging for version mismatch issues
- Clear error messages for troubleshooting
-
Delete old pickle files from your repository:
git rm artifacts/model.pkl artifacts/preprocessor.pkl git commit -m "Remove old pickle files - will regenerate on deployment" git push -
Configure Render:
- Build Command:
bash build.sh - Start Command:
bash start.sh
- Build Command:
-
Deploy - The build script will automatically retrain models with the correct sklearn version
If you want to keep artifacts in git but force retrain:
-
Modify build.sh to always retrain:
# Remove the condition check, always retrain echo "Retraining models..." python retrain_models.py
-
Configure Render:
- Build Command:
bash build.sh - Start Command:
bash start.sh
- Build Command:
-
Deploy
Set these in Render dashboard if needed:
PYTHON_VERSION:3.10.x(or your preferred version)PORT: Auto-assigned by Render
# Create fresh virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# This regenerates all pickle files with current sklearn version
python retrain_models.py# Development mode
python app.py
# Production mode (local testing)
gunicorn --bind 0.0.0.0:8000 --workers 2 --timeout 120 app:appVisit: http://localhost:8000 (or 5000 for development mode)
Solution: Delete artifacts folder on Render and redeploy
Solution: Increase build timeout in Render settings (Settings > Build & Deploy)
Solution: Verify requirements.txt includes all dependencies and setup.py is configured correctly
Solution: Make scripts executable:
chmod +x build.sh start.sh
git add build.sh start.sh
git commit -m "Make scripts executable"
git push- ✅
requirements.txt- Pinned all dependencies - ✅
build.sh- Automated build script - ✅
start.sh- Production start script - ✅
retrain_models.py- Model retraining script - ✅
src/utils.py- Enhanced error handling - ✅
.gitignore- Documentation for artifacts
Render Deployment Flow:
1. git push → Trigger deployment
2. build.sh → Install dependencies
3. build.sh → Check for artifacts
4. build.sh → Retrain if needed (runs retrain_models.py)
5. start.sh → Launch gunicorn server
6. App ready! ✅
- Always pin dependencies - Never use unpinned versions in production
- Test locally first - Use the retrain script before deploying
- Monitor logs - Check Render logs for any warnings
- Version control - Keep track of sklearn version used for training
- Regular updates - Update dependencies together and retrain all models
# Retrain locally
python retrain_models.py
# Test locally with gunicorn
gunicorn --bind 0.0.0.0:8000 app:app
# Deploy to Render (after push)
git add .
git commit -m "Update deployment configuration"
git push origin mainIf issues persist:
- Check Render build logs
- Verify Python version matches local environment
- Ensure all dependencies installed successfully
- Try manual retraining on Render console