A complete reference for every input field, feature contribution, preprocessing pipeline, and model performance behind the ShopperAI purchase prediction system.
The Online Shoppers Intention dataset was collected from an e-commerce platform over one year. Each row represents a single browsing session, and the goal is to predict whether that session will end in a purchase.
balanced weightsOnly ~15.5% of sessions result in a purchase. This imbalance was addressed using class_weight="balanced" in tree-based models and optimizing for PR-AUC (Precision-Recall Area Under Curve) instead of accuracy, which is a more informative metric for imbalanced datasets.
These are the raw features available from the dataset that are sent directly to the prediction API. Impact levels reflect observed influence on the Revenue target.
| Field Name | Type | Description | Range | Impact |
|---|---|---|---|---|
| PageValues | float | Average value of pages viewed before completing an e-commerce transaction. Pages contributing to a purchase are weighted by their transactional value. | 0 – 361.76 | |
| ProductRelated | int | Number of product-related pages visited during the session. High counts indicate active product exploration. | 0 – 705 | |
| ProductRelated_Duration | float | Total time (seconds) spent on product-related pages. Longer time suggests deeper product consideration. | 0 – 63,974 s | |
| BounceRates | float | Percentage of visitors who enter and immediately exit the site from that page, without any further interaction. Lower values indicate more engaged visitors. | 0.0 – 0.20 | |
| ExitRates | float | For each page, the percentage of all sessions that ended on that page. Different from bounce rate — applies even if the user visited other pages first. | 0.0 – 0.20 | |
| Administrative | int | Number of administrative pages visited (e.g. account management, order history, settings pages). | 0 – 27 | |
| Administrative_Duration | float | Total time (seconds) spent on administrative pages during the session. | 0 – 3,399 s | |
| Informational | int | Number of informational pages visited (e.g. about us, contact, FAQ, shipping info). | 0 – 24 | |
| Informational_Duration | float | Total time (seconds) spent on informational pages during the session. | 0 – 2,549 s | |
| SpecialDay | float | Indicates how close the session date is to a special shopping day (e.g. Mother's Day, Valentine's). 0.0 = not close, 1.0 = very close. | 0.0 – 1.0 |
| Field Name | Type | Description | Values | Impact |
|---|---|---|---|---|
| VisitorType | string | Whether the visitor is returning to the site or visiting for the first time. Returning visitors tend to have higher purchase intent. | Returning_Visitor New_Visitor Other |
|
| Month | string | Month of the year the session occurred. Seasonality plays a role — November and December show higher purchase rates due to holidays. | Feb, Mar, May, June, Jul, Aug, Sep, Oct, Nov, Dec |
|
| TrafficType | int code | Integer code representing how the visitor arrived at the site (e.g. direct, referral, paid search, social media). Different traffic sources have different conversion rates. | 1 – 20 | |
| Region | int code | Geographic region of the visitor (anonymized integer code). Regional purchasing patterns may vary significantly. | 1 – 9 | |
| OperatingSystems | int code | Operating system used by the visitor (anonymized integer code). Device type inferred from OS may weakly correlate with purchase behavior. | 1 – 8 | |
| Browser | int code | Browser used by the visitor (anonymized integer code). Has minimal direct predictive power but contributes marginally to the model. | 1 – 13 | |
| Weekend | boolean | Whether the session occurred on a weekend. Weekday vs weekend browsing patterns differ slightly in conversion likelihood. | true / false |
PageValues is technically a data leakage candidate — it's computed using transactional data that only exists after a purchase. In real-time prediction, this value may be 0 for all sessions (since no transaction has occurred yet). For demo purposes the API accepts it, and non-zero values will strongly push the prediction toward "Will Purchase".
These features were derived from the raw inputs to capture richer behavioral signals. They are computed automatically inside the model pipeline — you do not need to provide them as inputs.
The model uses a sklearn Pipeline that automatically handles imputation, encoding, and scaling before feeding data to the classifier.
TotalDuration, TotalPages, ratios, engagement scores, and log-transformed duration features are derived from the raw 17 inputs. This step adds 20+ additional features that help the model capture non-linear behavioral patterns.
Numerical columns use median imputation (robust to outliers). Categorical columns use most-frequent imputation. The dataset had a small percentage of missing values in numeric features only.
RobustScaler is used instead of StandardScaler because duration and page-count features contain significant outliers. RobustScaler centers using the median and scales using the IQR, making it resistant to extreme values.
OneHotEncoder with min_frequency=10 is applied to Month, VisitorType, Weekend, and the integer-code columns (OperatingSystems, Browser, Region, TrafficType). Rare categories are grouped as "infrequent."
A ColumnTransformer applies the numeric and categorical pipelines in parallel and combines the results into a single feature matrix before passing to the classifier.
The preprocessed features are fed into the best-performing classifier. All steps — including feature engineering — are serialized into a single .pkl file so the API only needs raw inputs.
All models were evaluated using 5-fold Stratified Cross-Validation with PR-AUC as the scoring metric, followed by hyperparameter tuning via RandomizedSearchCV.
With 84.5% of sessions being non-purchases, a naive model predicting "no purchase" every time would achieve 84.5% accuracy — but be completely useless. PR-AUC measures performance specifically on the minority (purchase) class, penalizing models that simply predict the majority class and rewarding those that correctly identify true buyers.
Performance on the held-out test set (20% of data, ~2,445 sessions), never seen during training or hyperparameter tuning.
The model outputs a probability score between 0 and 1. A decision threshold converts this into a binary prediction.
The threshold was tuned by sweeping values from 0.05 to 0.90 and selecting the threshold that maximizes the F1-score on the purchase class. At 0.49 the model achieves the best balance between Precision (72%) and Recall (64%), slightly favoring capturing more true buyers at the cost of a few extra false alarms.
Send a POST request with a JSON body containing all 17 input fields. The API returns a probability score, label, and threshold.
GET https://xstynwx-online-shoppers-api.hf.space/health — returns 200 OK with a status message when the API is running.
FastAPI auto-generates Swagger UI at /docs. Test the API directly from your browser without writing any code.