β Cafe Sales β Random Forest Regressor
A tuned Random Forest Regressor trained on cafe transaction data to predict Total Spent per transaction.
π Dataset
| Property |
Value |
| Source |
Cafe Sales Dataset |
| Rows |
9,540 transactions |
| Target |
Total Spent (in currency units) |
π§ Features Used
| Feature |
Type |
| Item |
Categorical (Coffee, Cake, Cookie, etc.) |
| Quantity |
Numeric |
| Payment Method |
Categorical (Cash, Credit Card, Digital Wallet) |
| Location |
Categorical (In-store, Takeaway) |
| Day of Week |
Numeric (0=Mon, 6=Sun) |
| Month |
Numeric (1β12) |
| Is Weekend |
Binary (0/1) |
Price Per Unit was intentionally dropped to avoid trivial prediction (Total Spent = Qty Γ PPU).
βοΈ Best Hyperparameters (via RandomizedSearchCV, cv=5)
n_estimators = 300
max_depth = 10
min_samples_split = 10
min_samples_leaf = 2
max_features = 0.5
π Evaluation Metrics (Test Set β 20%)
| Metric |
Default RF |
Tuned RF |
| MAE |
0.7800 |
0.7007 |
| RMSE |
1.8726 |
1.6997 |
| RΒ² |
0.8959 |
0.9142 |
π Usage
import joblib
import pandas as pd
from huggingface_hub import hf_hub_download
model_path = hf_hub_download(
repo_id="rohansuyal/cafe-sales-rf-regressor",
filename="rf_tuned_model.pkl"
)
model = joblib.load(model_path)
sample = pd.DataFrame([{
"Item": "Coffee",
"Quantity": 2.0,
"Payment Method": "Cash",
"Location": "In-store",
"Day_of_Week": 0,
"Month": 6,
"Is_Weekend": 0
}])
prediction = model.predict(sample)
print(f"Predicted Total Spent: {prediction[0]:.2f}")
π οΈ Tech Stack
- Python 3.10
- scikit-learn β RandomForestRegressor, Pipeline, ColumnTransformer
- pandas / numpy β Data processing
- joblib β Model serialization
π Files
| File |
Description |
rf_tuned_model.pkl |
Trained pipeline (preprocessor + model) |
README.md |
This file |