This project tackles a classic problem in the food-tech industry: Predicting the success of a restaurant based on its features.
Using the Zomato Bangalore dataset, we built a machine learning pipeline to predict the Rating (1-5) of a restaurant using two approaches:
Regression: Predicting the exact rating (e.g., 4.1 vs 3.8).
Classification: Predicting if a restaurant is "Recommended" (>3.75) or not.
🔍 Part 1: EDA & Baseline Model
We started by analyzing the data distributions to understand what drives a high rating.
🧹 Data Cleaning & Preprocessing
To ensure data quality, we performed the following steps:
Missing Values: Dropped records with missing rate (target variable) as they constitute a small portion of the data. For missing approx_cost, we imputed values using the median cost of the specific sub-zone.
Duplicate Entries: Identified and removed duplicate rows to prevent data leakage between train and test sets.
Data Types: Converted rate from string (e.g., "4.1/5") to float, and cleaned cost by removing currency symbols and commas.
Key Factors Analysis
Before modeling, we visualized the relationship between ratings and key operational features.
Rating Analysis
Insights from the graph above:
Distribution: Ratings are slightly left-skewed, with most restaurants scoring between 3.2 and 4.2.
Table Booking (The "Premium" Effect): This was a major differentiator. As seen in the bottom-right boxplot, restaurants that offer table booking (1) have a significantly higher median rating (4.2) compared to those that don't (3.6).
Cost vs. Rating: There is a positive correlation; generally, higher cost implies higher ratings, though variance exists.
Data Cleaning (Handling Outliers)
While analyzing costs, we noticed significant outliers that could skew our predictions. As seen below, the cost distribution required normalization.
Cost Boxplot
The Baseline (Linear Regression)
We trained a simple Linear Regression model on the raw data to establish a baseline. The results were poor ($R^2 = 0.28$), confirming that the relationships are non-linear and that extensive feature engineering is required.
Baseline Model
⚙️ Part 2: Feature Engineering & Clustering
To improve performance, we applied:
Log Transformation: To normalize votes and cost.
Target Mean Encoding: For high-cardinality categorical features (cuisines, location).
K-Means Clustering: To create a new feature representing business profiles.
📈 Ablation Study - What made the difference?
The jump from a baseline $R^2$ of 0.28 to the final 0.93 was not magic. Our analysis showed that Target Encoding on the cuisines feature provided the most significant performance boost (improving $R^2$ by ~0.4), followed by the K-Means Cluster feature which helped the model distinguish between different restaurant business models.
💡 Cluster Analysis
Using the Elbow Method, we identified K=6 as the optimal number of clusters.
Elbow Method
We visualized these clusters using PCA (Principal Component Analysis), which showed distinct separation between different market segments (e.g., Budget Delivery vs. Premium Dining).
PCA Clusters
🧩 Decoding the Clusters (Business Profiles)
The K-Means analysis (K=6) provided a granular segmentation of the market. By analyzing the centroids, we identified 6 distinct restaurant archetypes:
The Elite (Premium Dining): High cost, exclusive Table Booking availability, and consistently high ratings.
The "Legends" (Viral): Restaurants with an extreme number of Votes. These are established brands where social proof drives the rating.
Hidden Gems: Low-to-medium cost establishments that manage to achieve high ratings despite lacking premium features.
The Risky / Low Quality: Low cost and low ratings. The model learned to identify these as "avoidable" options.
Mainstream Casual: The largest cluster. Mid-range prices, good for delivery (Online Order), with average ratings (~3.5-3.9).
Overpriced / Underperforming: Restaurants with higher costs but surprisingly mediocre ratings/votes, distinguishing them from the true "Elite".
🧠 Part 3: Regression Models (Predicting the Score)
We trained three models on the engineered data: Linear Regression, Decision Tree, and Random Forest.
Model Comparison ($R^2$ Score)
The Feature Engineering provided a massive boost, with Random Forest emerging as the clear winner.
Model Comparison
The Winner: Random Forest Regressor 🏆
$R^2$ Score: 0.93
RMSE: 0.11
What drives a high rating?
According to the Feature Importance plot below, the specific Cuisine and the number of Votes (Social Proof) are the most critical factors. Interestingly, while Table Booking was visually distinct in EDA, the model found that purely content-based features (Cuisine/Votes) hold more predictive power.
Feature Importance
Accuracy Check (Actual vs. Predicted):
The points align perfectly on the red diagonal line, showing high prediction accuracy.
RF Prediction
📉 Error Analysis: Where does the model fail?
Despite high accuracy, manual inspection of the errors revealed two patterns:
The "Newbie" Problem: Restaurants with very few votes (<10) are harder to predict, as the social proof signal is weak.
The "Expectation Gap": Some high-cost restaurants received surprisingly low ratings (likely due to high expectations not being met). The model occasionally predicted higher ratings for these based on their premium features (price, booking availability), missing the specific negative sentiment.
⚖️ Part 4: Classification (Recommended vs. Not)
We reframed the problem to answer a business question: "Should we recommend this restaurant?"
Threshold: 3.75 (Median split).
Goal: Maximize Precision for Class 1 (Good). We want to avoid recommending bad restaurants (False Positives) at all costs.
Class Balance
The data is well balanced between "Low" (0) and "High" (1) rated restaurants.
Class Balance
Model Evaluation (Confusion Matrices)
1. Logistic Regression (Baseline):
Precision is 0.86. Decent, but too many errors.
Logistic Regression
2. XGBoost:
Precision is 0.95. Very strong.
XGBoost
3. Random Forest (Winner 🏆):
Precision is 0.98. The model almost never recommends a bad restaurant.
Random Forest CM
🚀 Conclusion
We successfully built a robust predictor.
Feature Engineering (specifically Target Encoding and Clustering) improved the model from $R^2=0.28$ to $R^2=0.93$.
Random Forest proved to be the best algorithm for this dataset, handling the non-linear relationships better than Linear Regression and slightly outperforming XGBoost.
📂 Repository Structure
notebook.ipynb: The complete Python code for the project.
zomato_rf_model.pkl: The winning Regression model.
zomato_classification_model.pkl: The winning Classification model.