# 066. Completed-session purchase classification

**Question:** How well can a model classify purchase sessions without PageValues?

## Result

The largest computed metric is 0.3645 for Random forest; the smallest is 0.1495 for Prior baseline. Metric: average_precision (Average precision).

This is completed-session classification, not real-time conversion forecasting. Exact input duplicates are grouped.

![Completed-session purchase classification](outputs/chart.png)

| model | accuracy | balanced_accuracy | macro_f1 | roc_auc | average_precision | brier |
| --- | --- | --- | --- | --- | --- | --- |
| Prior baseline | 0.8505 | 0.5 | 0.4596 | 0.5 | 0.1495 | 0.1272 |
| Logistic regression | 0.8493 | 0.5038 | 0.4698 | 0.7342 | 0.2881 | 0.1171 |
| Random forest | 0.8505 | 0.5225 | 0.5084 | 0.7748 | 0.3645 | 0.1109 |

The chart shows 3 of 3 result rows; the table previews the first 3 in the analysis-defined order. [Download the full result table](outputs/results.csv). Numerical values are computed from the source; missing results stay unavailable.

## Method

Fixed grouped-input train/test benchmark with a prior baseline.

The study uses shared source preparation and reusable statistical routines. Its specific transformations are in [analysis.py](analysis.py), and common model/evaluation code is in [portfolio/methods.py](../../portfolio/methods.py). The [notebook](analysis.ipynb) executes the study and displays the saved results.

## Evaluation

Fixed 80/20 split of unique input groups (seed 42); exact input duplicates stay together. Training observations: 9,875; test observations: 2,455. Fixed models; default decision threshold; no holdout tuning.

Target: `revenue`. Features: administrative, administrative_duration, informational, informational_duration, productrelated, productrelated_duration, bouncerates, exitrates, specialday, month, operatingsystems, browser, region, traffictype, visitortype, weekend. Model results and row membership are recorded in [evaluation.json](outputs/evaluation.json).

## Decision and limitations

Use the benchmark to study session behavior; obtain time-stamped partial-session data for any earlier intervention.

One observation is a completed session. End-of-session behavior cannot support an early-session prediction claim. PageValues is excluded from purchase models because it can encode downstream purchase information. Associations are not experiment results. 

Related studies may share observations or holdouts. These are focused analytical studies, not independent replications or deployed business systems. Any model refinements informed by these results need new untouched evaluation data. No commercial impact is inferred from an association or backtest.

## Reproduce

From the repository root, after installing `requirements.txt`:

```powershell
python projects/066-completed-session-purchase-classification/analysis.py
```

Source data are downloaded automatically if absent. Original archives are retained unchanged and checked by SHA-256. The cleaned cache normalizes column names; field-specific changes are visible in [data preparation](../../portfolio/data.py). Runtime evidence is in [receipt.json](outputs/receipt.json).

## Source

[Online Shoppers Purchasing Intention](https://archive.ics.uci.edu/dataset/468/online+shoppers+purchasing+intention+dataset), Sakar and Kastro (2018). [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). Source data are transformed and aggregated in this study. [Source provenance](../../data/provenance/shoppers.json) and [prepared-data audit](../../data/provenance/shoppers_prepared.json) record the downloaded files, field coverage and hashes.
