A comprehensive data science project that predicts bike sharing demand using machine learning, featuring a modern web interface, REST API, and comprehensive testing suite.
- Overview
- Features
- Project Structure
- Installation
- Usage
- API Documentation
- Model Details
- Testing
- Technologies Used
- Contributing
- License
This project models the demand for shared bikes using various independent variables. It helps management understand how demand varies with different features, enabling them to manipulate business strategies to meet demand levels and customer expectations. The model also provides insights into demand dynamics for new markets.
- Company: BoomBikes (US bike-sharing provider)
- Challenge: Revenue dips due to COVID-19 pandemic
- Goal: Understand post-pandemic bike sharing demand patterns
- Dataset: Daily bike rental data with weather, seasonal, and temporal features
- Responsive Design: Works on desktop, tablet, and mobile
- Interactive Forms: Real-time validation and user feedback
- Animated Predictions: Smooth number animations for results
- Sample Data: One-click sample data loading for testing
- Modern UI: Clean, professional design with gradient backgrounds
- RESTful API: Clean, well-documented endpoints
- Input Validation: Comprehensive data validation
- Error Handling: Graceful error responses
- Health Checks: System monitoring endpoints
- Scalable Architecture: Modular, maintainable code
- Unit Tests: Individual component testing
- Integration Tests: End-to-end workflow testing
- Edge Case Testing: Boundary value testing
- API Testing: Complete endpoint coverage
- Model Testing: Prediction accuracy validation
- Linear Regression: Interpretable coefficients
- Feature Engineering: Categorical variable encoding
- Statistical Analysis: VIF, p-values, RΒ² scores
- Performance Metrics: ~83% accuracy on test data
Bike-sharing/
βββ app.py # Flask application and API endpoints
βββ test_app.py # Comprehensive test suite
βββ requirements.txt # Python dependencies
βββ setup.py # Setup and installation script
βββ pyproject.toml # Project configuration
βββ README.md # This file
βββ bike.ipynb # Original Jupyter notebook analysis
βββ templates/
β βββ index.html # Main web interface
βββ static/
β βββ style.css # Modern CSS styling
β βββ script.js # Interactive JavaScript
βββ logs/ # Application logs (created on run)
- Python 3.8 or higher
- pip (Python package installer)
-
Clone the repository
git clone https://github.com/vannu07/Bike-sharing.git cd Bike-sharing -
Run the setup script
python setup.py
-
Install dependencies
pip install -r requirements.txt
-
Run tests
python -m pytest test_app.py -v
-
Start the application
python app.py
-
Start the application
python app.py
-
Open your browser Navigate to
http://localhost:5000 -
Fill the form
- Select date and time information
- Enter weather conditions
- Choose seasonal factors
- Click "Predict Bike Demand"
-
View results
- See animated prediction results
- Review model insights
- Use sample data for testing
curl -X POST http://localhost:5000/predict \
-H "Content-Type: application/json" \
-d '{
"year": 1,
"month": "Jul",
"weekday": "Mon",
"temperature": 25.0,
"humidity": 60.0,
"windspeed": 10.0,
"weather": "Clear",
"season": "Summer",
"holiday": 0,
"workingday": 1
}'curl http://localhost:5000/health- Description: Main web interface
- Response: HTML page with prediction form
- Description: Predict bike sharing demand
- Request Body:
{ "year": 0|1, // 0=2018, 1=2019 "month": "Jan|Feb|...", // Month name "weekday": "Mon|Tue|...", // Day of week "temperature": float, // Temperature in Β°C "humidity": float, // Humidity percentage (0-100) "windspeed": float, // Wind speed in km/h "weather": "Clear|Light_rainfall|Thunderstrom", "season": "Spring|Summer|Fall|Winter", "holiday": 0|1, // Is holiday "workingday": 0|1 // Is working day } - Response:
{ "prediction": 1234, // Predicted bike rentals "status": "success" }
- Description: System health check
- Response:
{ "status": "healthy" }
cnt = 0.3535 + 0.228*yr + 0.526*temp - 0.189*hum - 0.165*windspeed
- 0.113*Spring + 0.045*Winter - 0.59*Aug - 0.124*Jul
- 0.05*Jun - 0.045*Light_rainfall - 0.203*Thunderstrom
- Temperature Impact: Strong positive correlation (coefficient: 0.526)
- Year Growth: Significant growth year-over-year (coefficient: 0.228)
- Weather Sensitivity: Storms reduce demand significantly (coefficient: -0.203)
- Seasonal Patterns: Summer/Fall show higher activity
- Model Performance: RΒ² = 0.834 on test data
- Categorical Encoding: One-hot encoding for seasons, months, weather
- Scaling: MinMax scaling for numerical features
- Feature Selection: RFE (Recursive Feature Elimination)
- Multicollinearity: VIF analysis and removal
python -m pytest test_app.py -v- Unit Tests: Individual component testing
- Integration Tests: End-to-end workflow testing
- API Tests: HTTP endpoint testing
- Model Tests: Prediction accuracy validation
- Edge Case Tests: Boundary value testing
- β Predictor class initialization
- β Input preprocessing
- β Prediction functionality
- β Flask app endpoints
- β Error handling
- β Edge cases and boundary values
- β Model consistency
- β Integration workflows
- Flask 2.3.3: Web framework
- Pandas 1.5.3: Data manipulation
- NumPy 1.24.4: Numerical computing
- Scikit-learn 1.3.0: Machine learning
- Statsmodels 0.14.0: Statistical analysis
- HTML5: Semantic markup
- CSS3: Modern styling with gradients and animations
- JavaScript: Interactive functionality
- Font Awesome: Icons and UI elements
- Pytest 7.4.2: Testing framework
- Pytest-Flask: Flask-specific testing utilities
- Matplotlib 3.7.2: Plotting
- Seaborn 0.12.2: Statistical visualization
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
# Install development dependencies
pip install -e ".[dev]"
# Run tests with coverage
pytest --cov=app test_app.py
# Format code
black app.py test_app.py
# Lint code
flake8 app.py test_app.pyThis project is licensed under the MIT License - see the LICENSE file for details.
- Original analysis by @itsshaliniS
- Dataset from BoomBikes bike-sharing system
- Community contributions and feedback
- Project Maintainer: Data Science Team
- Email: [email protected]
- GitHub: @vannu07
β Star this repository if you found it helpful!