A full-stack Machine Learning web application that predicts the exact type of an Airbnb room based on its listing attributes.
- Project Overview
- Architecture & ML Pipeline
- Key Features
- Tech Stack
- Model Evaluation
- Folder Structure
- Installation & Local Setup
- Usage
- Future Improvements
The NYC Airbnb Room Type Classification project leverages real-world data from the New York City Airbnb Open Dataset. It frames a multi-class classification problem where the goal is to accurately predict the room_type of an Airbnb listing given its various characteristics (such as location, price, and review data).
The application offers an interactive front-end connecting to a FastAPI backend that exposes a robust and tuned machine learning model.
To predict whether an Airbnb listing is an Entire home/apt, a Private room, or a Shared room with high accuracy. This can help property owners determine how to list their rooms appropriately and can assist platforms with automated verification checks.
The full machine learning lifecycle from data ingestion to user prediction is handled efficiently:
graph TD
A[Raw Dataset<br>New York City Airbnb Open Data] --> B[Data Preprocessing<br>Missing Values, Outliers]
B --> C[Feature Engineering<br>Encoding, Scaling]
C --> D[Train/Test Split<br>80/20 Stratified]
D --> E[Model Training<br>Random Forest, Gradient Boosting, etc.]
E --> F[Hyperparameter Tuning<br>RandomizedSearchCV]
F --> G[Saved Model Artifact<br>Joblib Pipeline]
G --> H[FastAPI Backend<br>REST API]
H --> I[Web UI Application<br>Interactive Frontend]
I --> J[User Prediction]
- Data Preprocessing & Cleaning: Handling missing values, clipping outliers in price and stay duration.
- Feature Engineering: Using
ColumnTransformerfor robust scaling (StandardScaler) and One-Hot Encoding without data leakage. - Model Selection: Baselines were established using Logistic Regression, Decision Trees, Random Forest, and Gradient Boosting.
- Tuning: Utilizing
RandomizedSearchCVoptimizing for macro-F1 score to address class imbalances. - Serialization: Saving the entire inference pipeline (transformers + model) into
Model_Pipeline.pkl.
- Interactive UI: A highly polished, responsive frontend built with modern design principles and tailwind CSS.
- RESTful ML API: Serves predictions blazingly fast using a stateless
FastAPIinstance. - Data Preprocessing in Pipeline: The model takes raw input; all scaling and encoding are natively handled inside the serialized scikit-learn pipeline.
- Real-Time Predictions: Displays both the predicted class and the corresponding probabilities.
- Health Checks: Native
/healthendpoints to monitor the API status.
| Category | Technologies |
|---|---|
| Machine Learning | Scikit-Learn, Pandas, NumPy, Joblib |
| Backend API | Python, FastAPI, Pydantic, Uvicorn |
| Frontend UI | HTML5, CSS3, JavaScript (Vanilla), Tailwind CSS |
| Experimentation | Jupyter Notebooks |
| Deployment | Vercel (Frontend & Serverless API), Render (Backend API Support) |
The best performing model (a highly tuned Random Forest/Gradient Boosting algorithm) achieved the following results on the hold-out test set:
- Accuracy Score: ~85.6%
- Macro F1-Score: ~74.1%
The performance shows excellent capabilities in separating Entire homes and Private rooms, dealing well with the heavily imbalanced Shared room category thanks to hyperparameter tuning for the macro-F1 metric.
NYC_Airbnb_Room_Type_Classification/
โโโ docs/ # Documentation and Screenshots
โ โโโ screenshots/
โโโ frontend/ # UI application codebase
โ โโโ index.html # Web application entry point
โ โโโ script.js # Frontend logic and API integration
โ โโโ style.css # Styling and layout
โ โโโ tailwind.config.js
โโโ notebooks/ # ML exploration and training
โ โโโ nyc_airbnb_room_type_classification.ipynb
โโโ main.py # FastAPI application serving the model
โโโ Model_Pipeline.pkl # Serialized Scikit-Learn Pipeline
โโโ requirements.txt # Python dependencies
โโโ vercel.json # Deployment configuration
Want to run this project locally? Follow these steps:
git clone https://github.com/sumitjadhav1703/NYC_Airbnb_Room_Type_Classification.git
cd NYC_Airbnb_Room_Type_ClassificationCreate a virtual environment and install the required dependencies:
python3 -m venv environment_name
source environment_name/bin/activate # On Windows: environment_name\Scripts\activate
pip install -r requirements.txtStart the FastAPI backend locally on port 8000:
uvicorn main:app --reloadYou can verify the backend is running by navigating to http://localhost:8000/docs to see the Swagger UI.
Simply open the frontend/index.html file in your preferred web browser, or use a tool like Live Server.
(Note: The frontend is currently configured to ping the cloud API by default. For local testing, update API_BASE_URL in frontend/script.js to http://localhost:8000)
- Open the Live Web App.
- Fill out the Listing Characteristics (Latitude, Longitude, Price, Minimum Nights, Neighborhood, etc.).
- Click the "Predict Room Type" button.
- The backend model will instantly run inference and return the predicted room type (
Entire home/apt,Private room, orShared room) along with confidence probabilities!
While this project is fully functional, here are some great future enhancements that could be made:
- Dockerization: Containerizing the backend API and frontend for easier cloud deployments.
- MLflow Tracking: Utilizing tools like MLflow to track model experiments, parameters, and metrics systematically.
- Explainable AI (XAI): Integrating SHAP or LIME to provide users with explanations on why a particular room type was predicted.
- Batch Processing: Creating an endpoint to handle
.csvuploads for batch predictions.
Contributions are always welcome! If you have ideas for improvements:
- Fork the Project.
- Create your 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 repository does not currently contain a license file, but it is available as open source.
Built with โค๏ธ by Sumit Jadhav
