Used Car Market Explorer is a comprehensive data science project focused on analyzing and predicting used car prices in the Egyptian market. This project demonstrates the complete data science pipeline from web scraping to deployment, providing deep insights into market trends, price determinants, and offering an interactive web application for price prediction and car comparison.
This project uses publicly available car listings data from a popular automotive marketplace in Egypt that has been scraped strictly for research and educational purposes only. The web scraping component of this project:
- Follows ethical scraping practices with appropriate rate limiting to avoid overwhelming the server
- Respects robots.txt directives and website terms of service
- Is intended solely for educational demonstration of data science techniques
- Does not store or redistribute personal information of sellers or dealers
- Uses only publicly visible listing information
The scraping methodology adheres to responsible data collection practices and is designed to minimize any impact on the source website's performance.
-
π Ethical Web Scraping:
Responsibly extracts thousands of used car listings from automotive marketplace websites using Selenium and BeautifulSoup with proper rate limiting and robots.txt compliance. -
π§Ή Robust Data Cleaning & Preprocessing:
Handles missing values, removes duplicates, corrects data types, and filters outliers for reliable analysis. -
π Exploratory Data Analysis & Visualization:
Visualizes price trends, brand and city averages, and the impact of features like mileage and transmission type with Arabic language support. -
π€ Advanced Machine Learning Models:
Implements Ridge Regression and XGBoost for price prediction, with feature engineering and polynomial interactions. -
π Interactive Streamlit Web App:
- π Market Dashboard: Visualizes trends and key metrics
- π Data Exploration: Filter and browse the dataset
- π° Price Prediction: Predicts car prices using AI models
- βοΈ Car Comparison: Compares two car models side by side
- π Bilingual Support: Handles Arabic text for Egyptian market data
Htla2ee-Streamlit-app/
βββ π± app.py # Main Streamlit web application
βββ π requirements.txt # Python dependencies
βββ π README.md # Project documentation
βββ π data/
β βββ π processed/
β β βββ cleaned_data.csv # Cleaned dataset (CSV format)
β β βββ cleaned_data.xls # Cleaned dataset (Excel format)
β βββ π exports/
β βββ Used_Car_Analysis_Egypt.mydatabase.json # MongoDB export
βββ π notebooks/
β βββ 01_data_extraction.ipynb # Web scraping implementation
β βββ 02_data_cleaning.ipynb # Data preprocessing pipeline
β βββ 03_data_visulaization.ipynb # Exploratory data analysis
β βββ 04_price_prediction.ipynb # Machine learning models
β βββ 05_mongodb_integration.ipynb # Database integration
- Ethical Web Scraping:
Uses Selenium WebDriver to responsibly automate browsing and extract car details (brand, model, year, mileage, price, transmission, city, etc.) from automotive marketplace websites - Rate Limiting:
Implements appropriate delays between requests to avoid overwhelming the server - Robots.txt Compliance:
Respects website guidelines and scraping policies - Data Storage:
Saves raw data to CSV/Excel formats for further processing
- Null & Duplicate Handling:
Drops irrelevant columns, removes duplicates, and handles missing values appropriately - Type Conversion:
Converts price, year, and mileage to appropriate numeric types - Outlier Filtering:
Removes unrealistic values (e.g., mileage = 0, future years, extremely low prices) - Feature Engineering:
- Calculates car age from manufacturing year
- Encodes categorical variables (brand, model, city) using target encoding
- Log-transforms mileage for better distribution
- Handles rare models and transmission types
- Market Insights:
- Price depreciation analysis over years
- Average price comparison across brands and cities
- Transmission and fuel type distribution analysis
- Mileage impact on pricing
- Arabic Language Support:
- Proper rendering of Arabic city names and labels
- Bilingual visualization for Egyptian market context
- Feature Selection & Scaling:
Selects relevant features, applies standard scaling, and generates polynomial interaction terms - Model Implementation:
- Ridge Regression: Linear model with L2 regularization and hyperparameter tuning
- XGBoost Regressor: Gradient boosting for improved accuracy and feature importance
- Model Evaluation:
Cross-validation, RΒ² scoring, Mean Absolute Error (MAE), and performance comparison
- MongoDB Setup:
Stores processed data in MongoDB for scalable data management - Data Export:
Creates JSON exports for data sharing and backup
The interactive web application provides a user-friendly interface for exploring the used car market data and making price predictions.
-
π Main Dashboard:
Overview of the dataset, market statistics, and platform features -
π Data Exploration:
Interactive filters to browse and analyze the dataset with real-time updates -
π Data Visualization:
Dynamic charts and dashboards for market insights with Arabic language support -
π° Price Prediction:
- User-friendly input form for car specifications
- Instant price predictions from both Ridge and XGBoost models
- Confidence intervals and market comparisons
- Model performance metrics display
-
βοΈ Car Comparison:
Side-by-side comparison of two car models including:- Average price analysis
- Mileage statistics
- Transmission type distribution
- Geographic availability
- Python 3.8 or higher
- pip package manager
-
Clone the Repository
git clone https://github.com/khilo619/Htla2ee-Streamlit-app.git cd Htla2ee-Streamlit-app -
Install Dependencies
pip install -r requirements.txt
-
Launch the Streamlit App
streamlit run app.py
-
Access the Application
- Open your web browser and navigate to
http://localhost:8501 - The application will load with the main dashboard
- Open your web browser and navigate to
To explore the complete data science pipeline:
-
Install Jupyter
pip install jupyter
-
Launch Jupyter Notebook
jupyter notebook
-
Open and Run Notebooks
- Navigate to the
notebooks/directory - Run notebooks in sequence:
01_data_extraction.ipynbβ02_data_cleaning.ipynbβ03_data_visualization.ipynbβ04_price_prediction.ipynbβ05_mongodb_integration.ipynb
- Navigate to the
Our machine learning models demonstrate strong predictive capabilities for the Egyptian used car market:
-
π΅ Ridge Regression:
- RΒ² Score: ~0.85 (Explains 85% of price variance)
- Mean Absolute Error: ~15%
- Strengths: Stable predictions, good generalization
-
π’ XGBoost Regressor:
- RΒ² Score: ~0.91 (Explains 91% of price variance)
- Mean Absolute Error: ~9.7%
- Strengths: Higher accuracy, captures complex feature interactions
- Brand Impact: Luxury brands (Mercedes, BMW, Audi) command premium prices
- Depreciation: Cars lose approximately 15-20% value per year
- Geographic Variation: Cairo and Alexandria show higher average prices
- Mileage Effect: Exponential price decrease with higher mileage
- Transmission Preference: Automatic transmission preferred in premium segment
- Python 3.8+ - Primary programming language
- Streamlit 1.36.0 - Web application framework
- Pandas 2.2.2 - Data manipulation and analysis
- NumPy 1.26.4 - Numerical computing
- Scikit-learn 1.5.0 - Machine learning library
- XGBoost 2.0.3 - Gradient boosting framework
- Plotly 5.22.0 - Interactive visualizations
- Matplotlib 3.8.4 - Static plotting
- Seaborn 0.13.2 - Statistical visualizations
- Selenium - Browser automation
- BeautifulSoup - HTML parsing
- Requests - HTTP library
- OpenPyXL 3.1.2 - Excel file handling
- Arabic-reshaper & python-bidi - Arabic text processing
This project serves as a comprehensive educational resource demonstrating:
-
Ethical Web Scraping Practices
- Responsible data collection methodologies
- Rate limiting and server respect
- Robots.txt compliance
-
Complete Data Science Pipeline
- Data extraction and cleaning
- Exploratory data analysis
- Feature engineering
- Model development and evaluation
-
Real-world Application Development
- Interactive web application design
- User experience considerations
- Deployment-ready code structure
-
Market Analysis Techniques
- Price prediction modeling
- Market trend analysis
- Comparative analytics
This project was built collaboratively, dividing the data engineering and machine learning pipelines:
-
3blatif (@abdellatif72):
- Web Scraping & Data Pipeline: Engineered the ethical web scraping pipeline and overall data engineering workflow.
- Data Cleaning (Support): Assisted in the data cleaning and preprocessing phase alongside Yasser.
- Database Integration: Managed the MongoDB database integration.
-
Yasser (@yasserAker-sketch):
- Data Cleaning & Preprocessing: Led the data cleaning and preprocessing to prepare the dataset for analysis and modeling.
-
Islam (@IslamAhragab):
- Exploratory Data Analysis: Conducted in-depth EDA to surface key insights and patterns from the data.
-
KhaLood (@khilo619):
- Machine Learning: Built the full machine learning prediction models pipeline.
- Deployment: Built the interactive Streanlit appliction with market dashboard, price prediction, and car comparison features.
This is an educational project, but contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is developed strictly for educational and research purposes. The code and methodologies are provided as learning resources for:
- Data science students and professionals
- Web scraping education (with ethical considerations)
- Machine learning model development
- Interactive application design
- Source Data: Publicly available listings from Egyptian automotive marketplace websites
- Purpose: Educational demonstration and research only
- Compliance: Adheres to ethical scraping practices and robots.txt guidelines
- Privacy: No personal information of sellers/dealers is collected or stored
- Commercial Use: Not intended for commercial purposes
Users of this code are responsible for:
- Ensuring compliance with applicable laws and website terms of service
- Implementing appropriate rate limiting and respectful scraping practices
- Using the data responsibly and ethically
- Understanding that web scraping policies may change over time
- Data Source: Egyptian automotive marketplace - publicly available car listings
- Arabic Text Processing: Arabic-reshaper and python-bidi libraries for proper text rendering
- Machine Learning: Scikit-learn and XGBoost communities for excellent ML libraries
- Visualization: Plotly and Seaborn for powerful data visualization capabilities
- Web Framework: Streamlit team for the amazing web app framework
- Repository: GitHub - Htla2ee-Streamlit-app
- Issues: Please open an issue for bug reports or feature requests
- Educational Inquiries: Welcome for learning and academic purposes
β If this project helped you learn something new, please give it a star! β
Made with β€οΈ for the data science and web scraping education community
This app is ready for deployment on Hugging Face Spaces:
- Prepare your repository:
- Ensure
app.py,requirements.txt, andruntime.txtare in the root directory - Add your data files (or use a public data source)
- Ensure
- Create a new Space:
- Go to Hugging Face Spaces
- Select "Streamlit" as the SDK
- Link your repository or upload your files
- Configure:
- The app will automatically launch using
app.py - Make sure your requirements and runtime files are correct
- The app will automatically launch using
For more details, see the Hugging Face Streamlit deployment guide.
Authors: [KhaLood] & [3blatif]
Data Source: Hatla2ee
License: MIT