Downloads · 30 days
0
ROYFARGAN/rf_model
rf_model is a machine learning model from ROYFARGAN. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
This project applies end-to-end data science techniques to an e-commerce (Amazon-like) dataset in order to:
Downloads · 30 days
0
Access
Public
Updated Jan 22, 2026
Repo size
1.6 GB
Likes
0
Public
Click a slice to open those files.
.pkl1.6 GB · 99%
From the Hugging Face model README
This project applies end-to-end data science techniques to an e-commerce (Amazon-like) dataset in order to:
1.Predict the final order total (TotalAmount)** using regression models.
2.Segment orders/customers into spending tiers** (low / mid / high) using classification.
The work includes data cleaning, exploratory data analysis (EDA), feature engineering, clustering, regression modeling, classification modeling, and model deployment.
Source: Synthetic Amazon-style orders dataset (Amazon.csv).
Size: 100,000 rows.
Input features (examples):
Product: ProductID, ProductName, Category, Brand
Pricing: UnitPrice, Discount, Tax, ShippingCost
Quantity: Quantity
Transaction info: OrderDate, PaymentMethod, OrderStatus, City, Country, SellerID
TotalAmount – final amount paid for the order.The main research question:
Can we accurately predict the final order total (TotalAmount) of an Amazon order using customer, product, pricing, and transaction-level features?**
Key steps:
Data cleaning:
OrderDate as datetime.Week (ISO week number).Descriptive statistics:
UnitPrice:
TotalAmount (~0.72).Quantity:
TotalAmount grows almost linearly with Quantity.






-Outlier analysis:
Some very high totals due to combination of high UnitPrice & Quantity.
Kept most outliers, since they represent genuine high-value orders, which are important for modeling.
Seasonality / Black Friday analysis:
Week from OrderDate.TotalAmount than other weeks.3.1 Time-based features
Week: ISO week number for each order.IsHighSeason: 1 if Week in {47, 48} (Black Friday/Cyber Monday), else 0.3.2 Price-related flags
IsExpensiveItem: 1 if UnitPrice above median unit price, else 0.Note: To avoid data leakage, we did not include direct formulas that reconstruct TotalAmount (e.g., ValueBeforeTax = UnitPrice * Quantity * (1 − Discount)) in the final models.
3.3 Clustering-based features (Unsupervised Learning)
I applied K-Means clustering on standardized numerical features:
Features used for clustering:
UnitPrice, Quantity, Discount, Tax, ShippingCostSteps:
StandardScaler.KMeans(n_clusters=5, random_state=42).ClusterID – the cluster assignment for each order.DistanceToCentroid – Euclidean distance from each point to its cluster center.PCA Visualization:
PCA1, PCA2) and plotted the clusters.These cluster-derived features were then used as additional inputs to the regression and classification models.


TotalAmount)4.1 Baseline Linear Regression
UnitPrice, Quantity, Discount, Tax, ShippingCost, WeekCategory (one-hot encoded)random_state=42Interpretation:
The baseline model already explains ≈91% of the variance in TotalAmount, mainly driven by Quantity, UnitPrice, and Tax. Category has only a minor effect.
Using:
Week, IsHighSeason, IsExpensiveItem, ClusterID, DistanceToCentroidCategoryPerformance:
This shows a modest improvement over the baseline, primarily due to cluster-based segmentation and simple time-based flags.
I then trained two advanced models on the engineered dataset:
Results (approximate):
Because the underlying relationship between features and TotalAmount is nearly deterministic (a pricing formula applied consistently), tree-based models can almost perfectly reconstruct the function mapping inputs to target.
Winning Regression Model: Random Forest Regressor — near-perfect performance, robust to non-linearities and feature interactions.
I reframed the problem as a multi-class classification task, predicting spending tier class instead of continuous TotalAmount.
I converted TotalAmount into three classes using quantile-based binning on the training set:
TotalAmount < 443.53)443.53 ≤ TotalAmount < 1088.52)TotalAmount ≥ 1088.52)This ensures balanced classes and has a meaningful business interpretation: low-, mid-, and high-spending orders.
Class distribution:
Since the classes are well-balanced, accuracy and macro F1 are both appropriate evaluation metrics.
I trained three different classifiers using the same engineered feature set:
UnitPrice, Quantity, Discount, Tax, ShippingCost, Week, IsHighSeason, IsExpensiveItem, ClusterID, DistanceToCentroidCategory (one-hot encoded)All models used a ColumnTransformer + Pipeline for preprocessing and training.
ClusterID, DistanceToCentroid) and raw numeric inputs.Critical mistakes considered: In a business context, false negatives on the high-spending class (Class 2 → Class 0/1) are more costly than false positives, because they represent missed opportunities for targeting valuable customers.
Winning Classification Model: Random Forest Classifier — highest accuracy, macro F1, and most balanced confusion matrix.
The following models were exported as .pkl files for deployment:
winning_model_random_forest.pklrf_classifier_model.pkl