DDecisions · bandit.ope
Off-policy evaluation of a decision policy
How would a new decision policy have performed, judged only from decisions logged under the current one?
Estimates the average reward a new (target) policy would earn from logged data — the action shown, its reward and the logging policy's probability of showing it — before running the new policy live. Inverse propensity scoring (IPS), self-normalized IPS, clipped IPS, the direct method (a cross-fitted per-action reward model) and the doubly robust estimator, with bootstrap intervals from a shared seeded stream, the effective sample size and weight diagnostics.
A real result
Example “Rule linear”, recorded in both engines. In the app, “Try this example” loads it into Analyze.
The doubly robust estimate says the target policy would earn 0.406 per decision, 95% CI [0.365, 0.449], more than the 0.355 the logged policy earned (+0.050). 528 of 1,500 logged decisions agree with the target policy; the effective sample size of the importance weights is 512.
- Target policy value (doubly robust)
- 0.4058
- 95% CI
- [0.3648, 0.4489]
- Logged policy value
- 0.3553
- Effective sample size
- 512.15
Plots
View data
| Value | Upper | Estimator | Lower |
|---|---|---|---|
| 0.4272 | 0.4795 | IPS | 0.3794 |
| 0.4077 | 0.4501 | Self-normalized IPS | 0.3681 |
| 0.4272 | 0.4795 | Clipped IPS | 0.3794 |
| 0.4048 | 0.4086 | Direct method | 0.4010 |
| 0.4058 | 0.4489 | Doubly robust | 0.3648 |
| 0.3553 | 0.3773 | Logged policy | 0.3327 |
View data
| Weight |
|---|
| 2.738 |
| 2.599 |
| 2.539 |
| 3.901 |
| 2.743 |
| 2.452 |
| 3.771 |
| 2.856 |
| 2.771 |
| 2.367 |
| 3.006 |
| 4.434 |
| 3.892 |
| 2.665 |
| 3.166 |
| 2.663 |
| 3.958 |
| 2.659 |
| 2.929 |
| 2.788 |
| 2.925 |
| 2.666 |
| 4.537 |
| 3.740 |
| 3.866 |
| 2.982 |
| 2.762 |
| 2.823 |
| 3.090 |
| 2.325 |
| 3.121 |
| 3.025 |
| 2.500 |
| 2.847 |
| 2.877 |
| 2.344 |
| 2.664 |
| 2.845 |
| 2.400 |
| 1.957 |
| 2.266 |
| 4.013 |
| 2.682 |
| 2.747 |
| 2.821 |
| 2.806 |
| 2.310 |
| 2.872 |
| 2.789 |
| 2.520 |
| 2.506 |
| 2.852 |
| 2.633 |
| 2.527 |
| 2.925 |
| 2.540 |
| 3.654 |
| 2.946 |
| 3.399 |
| 2.856 |
First 60 of 528 rows.
Estimated value of the target policy
| Estimator | Estimate | SE | 95% CI low | 95% CI high | vs logged |
|---|---|---|---|---|---|
| IPS | 0.4272 | 0.0277 | 0.3794 | 0.4795 | 0.0719 |
| Self-normalized IPS | 0.4077 | 0.0218 | 0.3681 | 0.4501 | 0.0524 |
| Clipped IPS | 0.4272 | 0.0277 | 0.3794 | 0.4795 | 0.0719 |
| Direct method | 0.4048 | 0.0022 | 0.4010 | 0.4086 | 0.0495 |
| Doubly robust | 0.4058 | 0.0227 | 0.3648 | 0.4489 | 0.0505 |
Weight diagnostics
| Diagnostic | Value |
|---|---|
| Rows | 1,500 |
| Rows where target = logged action | 528 |
| Effective sample size | 512.15 |
| Mean weight (≈ 1 if propensities are right) | 1.048 |
| Largest weight | 4.986 |
| Smallest propensity | 0.1504 |
Actions: logged vs target policy
| offer | Logged share | Target share |
|---|---|---|
| A | 30.4% | 23.2% |
| B | 37.6% | 52.1% |
| C | 32.0% | 24.7% |
- Weights w = 1[target = logged action] / propensity. Reward model: linear in x1, spend ($), segment, cross-fitted over 2 folds; 400 bootstrap resamples of the per-row contributions (seed 42).
The doubly robust estimate says the target policy would earn 0.406 per decision, 95% CI [0.365, 0.449], more than the 0.355 the logged policy earned (+0.050). 528 of 1,500 logged decisions agree with the target policy; the effective sample size of the importance weights is 512.
- Target policy value (doubly robust)
- 0.4058
- 95% CI
- [0.3648, 0.4489]
- Logged policy value
- 0.3553
- Effective sample size
- 512.15
To keep this page light, the plots are shown once, under the R tab.
Estimated value of the target policy
| Estimator | Estimate | SE | 95% CI low | 95% CI high | vs logged |
|---|---|---|---|---|---|
| IPS | 0.4272 | 0.0277 | 0.3794 | 0.4795 | 0.0719 |
| Self-normalized IPS | 0.4077 | 0.0218 | 0.3681 | 0.4501 | 0.0524 |
| Clipped IPS | 0.4272 | 0.0277 | 0.3794 | 0.4795 | 0.0719 |
| Direct method | 0.4048 | 0.0022 | 0.4010 | 0.4086 | 0.0495 |
| Doubly robust | 0.4058 | 0.0227 | 0.3648 | 0.4489 | 0.0505 |
Weight diagnostics
| Diagnostic | Value |
|---|---|
| Rows | 1,500 |
| Rows where target = logged action | 528 |
| Effective sample size | 512.15 |
| Mean weight (≈ 1 if propensities are right) | 1.048 |
| Largest weight | 4.986 |
| Smallest propensity | 0.1504 |
Actions: logged vs target policy
| offer | Logged share | Target share |
|---|---|---|
| A | 30.4% | 23.2% |
| B | 37.6% | 52.1% |
| C | 32.0% | 24.7% |
- Weights w = 1[target = logged action] / propensity. Reward model: linear in x1, spend ($), segment, cross-fitted over 2 folds; 400 bootstrap resamples of the per-row contributions (seed 42).
Do it in CodeSplash Run it on your own data, in Python or R, with the code to prove it.
Worked examples in the app
- Rule linearo2_logged · action: offer · features: x1, spend ($), segment · propensity: propensity · reward: converted · target: new policy
- Always b meano2_logged · action: offer · propensity: propensity · reward: converted · target: always_b
- Uniform boolean rewardo2_uniform · action: button · features: u1, device type · propensity: propensity · reward: click · target: rule
- Degenerate single levelo2_logged · action: offer · features: x1, spend ($), segment · propensity: propensity · reward: converted · target: new policy
In the guides
Where it sits in the decision guides
- Reinforcement learning (bandits, RL) · DS & ML Decision Guide · Optimize / decide
- Prescriptive analytics (simulation, OR, causal RL) · DS & ML Decision Guide · Optimize / decide
What you need
- Logged actioncategorical / boolean · 1 column · 2–50 levels
- The action (offer, variant, treatment) the logging policy took on each row.
- Rewardnumeric / boolean · 1 column
- The observed reward of the logged action (e.g. converted, revenue).
- Logging propensitynumeric · 1 column
- The logging policy's probability of the logged action on that row (0 < p ≤ 1).
- Target policy's actioncategorical / boolean · 1 column
- The action the new policy would take on each row (same labels as the logged action).
- Context features (reward model)numeric / categorical / boolean · 0–50 columns
- Optional: features for the direct-method and doubly robust reward model (none = each action's mean).
Choices you make
options
- Reward model (DM / DR)default linear
Reward model used by the direct-method and doubly robust estimates: linear in the features, or the mean per action.
- Linear in the features (per action)(default) — Fits a linear reward model for each action; pick it when reward depends on the context.
- Mean reward per action — Uses each action's average reward; pick it when context matters little or rows are few.
- Cross-fitting foldsdefault 2
The reward model for each row is fit on the other folds (1 = in-sample).
- Weight cap for clipped IPSdefault 10
Caps importance weights so a few rarely chosen actions can't dominate the estimate (clipped IPS).
statistics
- Bootstrap resamplesdefault 1000
Number of bootstrap resamples. More gives steadier intervals but takes longer; use 1,000 or more for reporting.
- Confidence leveldefault 0.95
How sure the intervals should be: 0.95 gives 95% confidence intervals. Higher confidence means wider intervals.
What it reports
- value[ips]
- Estimates how a new decision policy would have done, using only logs from the current policy.
- value[snips]
- Estimates how a new decision policy would have done, using only logs from the current policy.
- value[dm]
- Estimates how a new decision policy would have done, using only logs from the current policy.
- value[dr]
- Estimates how a new decision policy would have done, using only logs from the current policy.
- ci_low[dr]
- A range of effect values compatible with your data at the chosen confidence level.
- ci_high[dr]
- A range of effect values compatible with your data at the chosen confidence level.
- logged_value
- Estimates how a new decision policy would have done, using only logs from the current policy.
- n
- How many independent units the analysis used; it sets precision and power.
- matched
- Estimates how a new decision policy would have done, using only logs from the current policy.
- ess
- How many equally weighted units a weighted sample is worth. Unequal weights make it smaller than the real count.
- mean_weight
- Estimates how a new decision policy would have done, using only logs from the current policy.
- max_weight
- Estimates how a new decision policy would have done, using only logs from the current policy.
Python and R
Python and R agree to 10 decimals (relative tolerance 1e-9). Python uses numpy, pandas, codesplash; R uses stats, nanoparquet, codesplashr.
Default traps between the two languages
- The linear reward model solves the ridge-stabilized normal equations with LAPACK in both engines (agreement ≈ 1e-14).
The exact script CodeSplash ran for example “Rule linear” · Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Off-policy evaluation of a decision policy
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method bandit.ope 1.0.1 · spec 7ba9eba7d39215ad
# Dataset: o2_logged (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.decide import ope # twin of codesplashr::cs_bandit_ope (shared-RNG folds and bootstrap)
# %% Data
df = pd.read_parquet("tests/parity/fixtures/o2_logged.parquet", columns=["offer", "converted", "propensity", "new policy", "x1", "spend ($)", "segment"])
n_input = len(df)
df["offer"] = pd.Categorical(df["offer"], categories=["A", "B", "C"]) # stored level order
df["new policy"] = pd.Categorical(df["new policy"], categories=["A", "B", "C"]) # stored level order
df["segment"] = pd.Categorical(df["segment"], categories=["new", "returning", "loyal"]) # stored level order
df = df.dropna(subset=["offer", "converted", "propensity", "new policy", "x1", "spend ($)", "segment"]) # listwise deletion over the analysis columns
df["offer"] = df["offer"].cat.remove_unused_categories()
df["new policy"] = df["new policy"].cat.remove_unused_categories()
df["segment"] = df["segment"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["offer", "converted", "propensity", "new policy", "x1", "spend ($)", "segment"]) # infinite values stop the run (registry/errors.yaml)
# %% Inputs
a_col, r_col, p_col, t_col = "offer", "converted", "propensity", "new policy"
features = ["x1", "spend ($)", "segment"]
model = "linear" # linear | mean
folds = int(2)
clip = 10 # None = no clipped IPS
n_boot = int(400)
conf = 0.95
seed = 42
levels = [str(x) for x in df[a_col].cat.categories]
action = df[a_col].astype(str).to_numpy()
target = df[t_col].astype(str).to_numpy()
# Yes/no rewards count as 1/0.
reward = (df[r_col].astype(str) == "true").astype(float).to_numpy() if isinstance(df[r_col].dtype, pd.CategoricalDtype) else df[r_col].to_numpy(dtype=float)
propensity = df[p_col].to_numpy(dtype=float)
numeric = [c for c in features if not isinstance(df[c].dtype, pd.CategoricalDtype)]
categorical = {c: [str(x) for x in df[c].cat.categories] for c in features if isinstance(df[c].dtype, pd.CategoricalDtype)}
x = ope.design(df, numeric, categorical) if features and model == "linear" else None
# Every action the target policy picks must be among the logged actions (first unknown one, in sorted order).
unknown = sorted(set(target) - set(levels))
if unknown:
cs.cs_error("CS_E_NOT_A_LEVEL", level=unknown[0], column=a_col)
# %% Estimate
res = ope.ope(action, reward, propensity, target, levels, x=x, model=model if features else "mean", folds=folds, clip=clip,
boot=n_boot, conf=conf, seed=seed)
warnings += res["warnings"]
n = res["n"]
if abs(res["mean_weight"] - 1) > 0.1:
warnings.append(f"The importance weights average {res['mean_weight']:.2f}, not 1: the propensities may be wrong, or the logging policy rarely takes the target's actions.")
if res["ess"] < 0.1 * n:
warnings.append(f"Effective sample size {res['ess']:.0f} is under 10% of the {n} rows: IPS-type estimates are noisy; prefer the doubly robust estimate.")
if res["max_weight"] > 50:
warnings.append(f"The largest weight is {res['max_weight']:.0f}: a few rows dominate IPS; compare with clipped IPS and DR.")
if not features:
warnings.append("No context features: the direct method uses each action's mean reward.")
# %% Result
lab = ope.LABELS
pct = f"{conf:.0%}"
dr, (dr_lo, dr_hi) = res["estimate"]["dr"], res["ci"]["dr"]
logged = res["logged"]
direction = "more" if dr > logged else "less"
summary = (
f"The doubly robust estimate says the target policy would earn {dr:.3f} per decision, {pct} CI [{dr_lo:.3f}, {dr_hi:.3f}], "
f"{direction} than the {logged:.3f} the logged policy earned ({dr - logged:+.3f}). {res['matched']:,} of {n:,} logged decisions agree with "
f"the target policy; the effective sample size of the importance weights is {res['ess']:.0f}."
)
rows = [
{"estimator": lab[e], "estimate": res["estimate"][e], "se": res["se"][e], "low": res["ci"][e][0], "high": res["ci"][e][1],
"diff": res["estimate"][e] - logged}
for e in res["estimators"]
]
values = {"logged_value": logged, "logged_ci_low": res["logged_ci"][0], "logged_ci_high": res["logged_ci"][1], "n": n,
"matched": res["matched"], "ess": res["ess"], "mean_weight": res["mean_weight"], "max_weight": res["max_weight"],
"min_propensity": res["min_propensity"], "improvement_dr": dr - logged}
for e in res["estimators"]:
values[f"value[{e}]"] = res["estimate"][e]
values[f"se[{e}]"] = res["se"][e]
values[f"ci_low[{e}]"] = res["ci"][e][0]
values[f"ci_high[{e}]"] = res["ci"][e][1]
forest_labels = [lab[e] for e in res["estimators"]] + ["Logged policy"]
matched_w = res["weights"][res["weights"] > 0]
cs.publish({
"method": "bandit.ope",
"methodVersion": "1.0.1",
"title": "Off-policy evaluation",
"engine": cs.engine_info("numpy", "pandas"),
"n": n,
"summary": summary,
"statistics": [
{"key": "dr", "label": "Target policy value (doubly robust)", "value": dr},
{"key": "ci", "label": f"{pct} CI", "value": [dr_lo, dr_hi]},
{"key": "logged", "label": "Logged policy value", "value": logged},
{"key": "ess", "label": "Effective sample size", "value": res["ess"]},
],
"tables": [
{"key": "estimates", "title": "Estimated value of the target policy",
"columns": [{"key": "estimator", "label": "Estimator", "type": "string"}, {"key": "estimate", "label": "Estimate", "type": "number"},
{"key": "se", "label": "SE", "type": "number"}, {"key": "low", "label": f"{pct} CI low", "type": "number"},
{"key": "high", "label": f"{pct} CI high", "type": "number"}, {"key": "diff", "label": "vs logged", "type": "number"}],
"rows": rows},
{"key": "diagnostics", "title": "Weight diagnostics",
"columns": [{"key": "metric", "label": "Diagnostic", "type": "string"}, {"key": "value", "label": "Value", "type": "number"}],
"rows": [{"metric": "Rows", "value": n}, {"metric": "Rows where target = logged action", "value": res["matched"]},
{"metric": "Effective sample size", "value": res["ess"]}, {"metric": "Mean weight (≈ 1 if propensities are right)", "value": res["mean_weight"]},
{"metric": "Largest weight", "value": res["max_weight"]}, {"metric": "Smallest propensity", "value": res["min_propensity"]}]},
{"key": "actions", "title": "Actions: logged vs target policy",
"columns": [{"key": "action", "label": a_col, "type": "string"}, {"key": "logged", "label": "Logged share", "type": "percent"},
{"key": "target", "label": "Target share", "type": "percent"}],
"rows": [{"action": lv, "logged": res["logged_share"][lv], "target": res["target_share"][lv]} for lv in levels]},
],
"warnings": warnings,
"notes": [
"Weights w = 1[target = logged action] / propensity. Reward model: " + f"{'linear in ' + ', '.join(features) if x is not None else 'mean reward per action'}"
+ (f", cross-fitted over {folds} folds" if folds > 1 else ", fit in-sample") + f"; {n_boot} bootstrap resamples of the per-row contributions (seed {seed}).",
],
"values": values,
"charts": [
cs.chart("estimates", "forest", "Estimated value per decision", {
"label": cs.col("Estimator", forest_labels, levels=forest_labels),
"estimate": cs.col("Value", [r["estimate"] for r in rows] + [logged]),
"low": cs.col("Lower", [r["low"] for r in rows] + [res["logged_ci"][0]]),
"high": cs.col("Upper", [r["high"] for r in rows] + [res["logged_ci"][1]]),
}, controls={"reference": logged}),
cs.chart("weights", "histogram", "Importance weights (rows where target = logged action)", {"x": cs.col("Weight", matched_w)}),
],
})
The exact script CodeSplash ran for example “Rule linear” · R version 4.5.1 (2025-06-13)
# Off-policy evaluation of a decision policy
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method bandit.ope 1.0.1 · spec 7ba9eba7d39215ad
# Dataset: o2_logged (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr) # cs_bandit_ope(): twin of codesplash.decide.ope (shared-RNG folds and bootstrap)
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/o2_logged.parquet", col_select = c("offer", "converted", "propensity", "new policy", "x1", "spend ($)", "segment")))
n_input <- nrow(df)
df[["offer"]] <- factor(df[["offer"]], levels = c("A", "B", "C")) # stored level order
df[["new policy"]] <- factor(df[["new policy"]], levels = c("A", "B", "C")) # stored level order
df[["segment"]] <- factor(df[["segment"]], levels = c("new", "returning", "loyal")) # stored level order
df <- df[stats::complete.cases(df[c("offer", "converted", "propensity", "new policy", "x1", "spend ($)", "segment")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("offer", "converted", "propensity", "new policy", "x1", "spend ($)", "segment")) # infinite values stop the run (registry/errors.yaml)
# %% Inputs
a_col <- "offer"
r_col <- "converted"
p_col <- "propensity"
t_col <- "new policy"
features <- c("x1", "spend ($)", "segment")
model <- "linear" # linear | mean
folds <- as.integer(2)
clip <- 10 # NULL = no clipped IPS
n_boot <- as.integer(400)
conf <- 0.95
seed <- 42
lv <- levels(df[[a_col]])
action <- as.character(df[[a_col]])
target <- as.character(df[[t_col]])
# Yes/no rewards count as 1/0.
reward <- if (is.factor(df[[r_col]])) as.numeric(as.character(df[[r_col]]) == "true") else as.numeric(df[[r_col]])
propensity <- as.numeric(df[[p_col]])
is_cat <- vapply(features, function(c) is.factor(df[[c]]), logical(1))
numeric_f <- features[!is_cat]
categorical_f <- lapply(stats::setNames(features[is_cat], features[is_cat]), function(c) levels(df[[c]]))
x <- if (length(features) && model == "linear") cs_bandit_design(df, numeric_f, categorical_f) else NULL
# Every action the target policy picks must be among the logged actions (first unknown one, in sorted order).
unknown <- sort(setdiff(unique(target), lv), method = "radix")
if (length(unknown)) cs_error("CS_E_NOT_A_LEVEL", level = unknown[1], column = a_col)
# %% Estimate
res <- cs_bandit_ope(action, reward, propensity, target, lv, x = x, model = if (length(features)) model else "mean", folds = folds,
clip = clip, boot = n_boot, conf = conf, seed = seed)
warnings <- c(warnings, as.list(res$warnings))
n <- res$n
if (abs(res$mean_weight - 1) > 0.1) {
warnings <- c(warnings, sprintf("The importance weights average %.2f, not 1: the propensities may be wrong, or the logging policy rarely takes the target's actions.", res$mean_weight))
}
if (res$ess < 0.1 * n) {
warnings <- c(warnings, sprintf("Effective sample size %.0f is under 10%% of the %d rows: IPS-type estimates are noisy; prefer the doubly robust estimate.", res$ess, n))
}
if (res$max_weight > 50) warnings <- c(warnings, sprintf("The largest weight is %.0f: a few rows dominate IPS; compare with clipped IPS and DR.", res$max_weight))
if (!length(features)) warnings <- c(warnings, "No context features: the direct method uses each action's mean reward.")
# %% Result
lab <- cs_bandit_ope_labels()
pct <- sprintf("%.0f%%", conf * 100)
dr <- res$estimate$dr
dr_ci <- res$ci$dr
logged <- res$logged
summary <- sprintf(
"The doubly robust estimate says the target policy would earn %.3f per decision, %s CI [%.3f, %.3f], %s than the %.3f the logged policy earned (%+.3f). %s of %s logged decisions agree with the target policy; the effective sample size of the importance weights is %.0f.",
dr, pct, dr_ci[1], dr_ci[2], if (dr > logged) "more" else "less", logged, dr - logged, format(res$matched, big.mark = ","),
format(n, big.mark = ","), res$ess
)
rows <- do.call(rbind, lapply(res$estimators, function(e) {
data.frame(estimator = lab[[e]], estimate = res$estimate[[e]], se = res$se[[e]], low = res$ci[[e]][1], high = res$ci[[e]][2],
diff = res$estimate[[e]] - logged)
}))
values <- list(logged_value = logged, logged_ci_low = res$logged_ci[1], logged_ci_high = res$logged_ci[2], n = n,
matched = res$matched, ess = res$ess, mean_weight = res$mean_weight, max_weight = res$max_weight,
min_propensity = res$min_propensity, improvement_dr = dr - logged)
for (e in res$estimators) {
values[[sprintf("value[%s]", e)]] <- res$estimate[[e]]
values[[sprintf("se[%s]", e)]] <- res$se[[e]]
values[[sprintf("ci_low[%s]", e)]] <- res$ci[[e]][1]
values[[sprintf("ci_high[%s]", e)]] <- res$ci[[e]][2]
}
forest_labels <- c(unname(lab[res$estimators]), "Logged policy")
matched_w <- res$weights[res$weights > 0]
fit_note <- if (!is.null(x)) paste("linear in", paste(features, collapse = ", ")) else "mean reward per action"
cs_publish(list(
method = "bandit.ope",
methodVersion = "1.0.1",
title = "Off-policy evaluation",
engine = cs_engine_info("stats", "codesplashr"),
n = n,
summary = summary,
statistics = list(
list(key = "dr", label = "Target policy value (doubly robust)", value = dr),
list(key = "ci", label = paste(pct, "CI"), value = dr_ci),
list(key = "logged", label = "Logged policy value", value = logged),
list(key = "ess", label = "Effective sample size", value = res$ess)
),
tables = list(
list(key = "estimates", title = "Estimated value of the target policy",
columns = list(list(key = "estimator", label = "Estimator", type = "string"), list(key = "estimate", label = "Estimate", type = "number"),
list(key = "se", label = "SE", type = "number"), list(key = "low", label = paste(pct, "CI low"), type = "number"),
list(key = "high", label = paste(pct, "CI high"), type = "number"), list(key = "diff", label = "vs logged", type = "number")),
rows = rows),
list(key = "diagnostics", title = "Weight diagnostics",
columns = list(list(key = "metric", label = "Diagnostic", type = "string"), list(key = "value", label = "Value", type = "number")),
rows = data.frame(metric = c("Rows", "Rows where target = logged action", "Effective sample size",
"Mean weight (≈ 1 if propensities are right)", "Largest weight", "Smallest propensity"),
value = c(n, res$matched, res$ess, res$mean_weight, res$max_weight, res$min_propensity))),
list(key = "actions", title = "Actions: logged vs target policy",
columns = list(list(key = "action", label = a_col, type = "string"), list(key = "logged", label = "Logged share", type = "percent"),
list(key = "target", label = "Target share", type = "percent")),
rows = data.frame(action = lv, logged = unname(res$logged_share[lv]), target = unname(res$target_share[lv])))
),
warnings = warnings,
notes = list(paste0("Weights w = 1[target = logged action] / propensity. Reward model: ", fit_note,
if (folds > 1) sprintf(", cross-fitted over %d folds", folds) else ", fit in-sample",
sprintf("; %d bootstrap resamples of the per-row contributions (seed %s).", n_boot, seed))),
values = values,
charts = list(
cs_chart("estimates", "forest", "Estimated value per decision", list(
label = cs_col("Estimator", forest_labels, levels = forest_labels),
estimate = cs_col("Value", c(rows$estimate, logged)),
low = cs_col("Lower", c(rows$low, res$logged_ci[1])),
high = cs_col("Upper", c(rows$high, res$logged_ci[2]))
), controls = list(reference = logged)),
cs_chart("weights", "histogram", "Importance weights (rows where target = logged action)", list(x = cs_col("Weight", matched_w)))
)
))
Sources
- Dudík, M., Langford, J., & Li, L. (2011). Doubly robust policy evaluation and learning. ICML, 1097–1104.
- Swaminathan, A., & Joachims, T. (2015). The self-normalized estimator for counterfactual learning. NeurIPS, 3231–3239.
- Saito, Y., Aihara, S., Matsutani, M., & Narita, Y. (2021). Open Bandit Dataset and Pipeline. NeurIPS Datasets and Benchmarks.
From the CodeSplash method registry · bandit.ope v1.0.1.