cleverly.datasets.learned_rule_truth#

cleverly.datasets.learned_rule_truth(result: Any, outcome_learner: Any) → float[source]#

Return the true value of the rules that a learned-rule fit of these data used.

A LearnedRuleValue fit learns one rule in each fold, from the outcome model fitted on the other folds, and reports a weighted average of the values of those rules. The fold-evaluated report weights each fold by 1/V, and the stacked report weights it by its share of the rows. This function refits outcome_learner on each fold’s training rows, checks that its rule matches the fit’s rule on every row of the fold, and averages the exact values of the refitted rules with the fit’s own fold weights. An in-sample fit (cross_fit=False) learns one rule on every row, and its target is the value of that one rule, which this function refits on every row.

Parameters:
resultEstimationResult

A LearnedRuleValue fit of a make_treatment_rules() draw, adjusted for need and lives_alone in that order.

outcome_learnerestimator

The outcome learner of the fit. It must be deterministic, so that a refit reproduces the fitted model.

Returns:
float

The average over the folds of treatment_rule_value() of each fold’s rule, with the weights result.extra["learned_rule"].splits[0].fold_weights.

Raises:
ValueError

When the fit is not an unweighted LearnedRuleValue fit of home_30 on offer with one split, adjusted for need and lives_alone, or a refitted rule differs from the fit’s rule on a row.

See also

cleverly.LearnedRuleValue

The estimand of the fit.