Skip to content

Commit 6371fb2

Browse files
docs(rlasso): add runnable Examples to RlassoRegressor/Classifier
Closes the examples_coverage ratchet (missing=2 -> 0) for the two scikit-learn learner classes from the hdm rlasso port; both blocks execute under check_example_execution. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent db77f78 commit 6371fb2

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/statspai/rlasso/learner.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ class RlassoRegressor(BaseEstimator, RegressorMixin):
6666
6767
Parameters mirror :func:`statspai.rlasso.rlasso`. Suitable as
6868
``ml_g`` / ``ml_m`` in ``sp.dml(model='plr', ...)``.
69+
70+
Examples
71+
--------
72+
>>> import statspai as sp
73+
>>> import numpy as np
74+
>>> rng = np.random.default_rng(0)
75+
>>> X = rng.standard_normal((100, 20))
76+
>>> beta = np.zeros(20); beta[:3] = [1.0, -1.0, 0.5]
77+
>>> y = X @ beta + 0.5 * rng.standard_normal(100)
78+
>>> est = sp.RlassoRegressor(post=True).fit(X, y)
79+
>>> est.predict(X).shape
80+
(100,)
81+
>>> est.coef_.shape
82+
(20,)
6983
"""
7084

7185
def __init__(
@@ -123,6 +137,18 @@ class RlassoClassifier(BaseEstimator, ClassifierMixin):
123137
Fits ``rlasso`` to the 0/1 label and exposes clipped
124138
``predict_proba``. Use only when a linear-probability propensity is
125139
acceptable; for calibrated propensities use a genuine classifier.
140+
141+
Examples
142+
--------
143+
>>> import statspai as sp
144+
>>> import numpy as np
145+
>>> rng = np.random.default_rng(0)
146+
>>> X = rng.standard_normal((200, 20))
147+
>>> lin = X[:, 0] - 0.5 * X[:, 1]
148+
>>> d = (rng.uniform(size=200) < 1.0 / (1.0 + np.exp(-lin))).astype(float)
149+
>>> clf = sp.RlassoClassifier().fit(X, d)
150+
>>> clf.predict_proba(X).shape # columns: P(0), P(1)
151+
(200, 2)
126152
"""
127153

128154
def __init__(

0 commit comments

Comments
 (0)