Skip to content

Commit 3dab6db

Browse files
Merge pull request h2oai#16003 from h2oai/sy-#15988-Isotonic
h2oaiGH-15988: Craft Isotonic Regression Examples
2 parents 3253c98 + 917254b commit 3dab6db

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
examples = dict(
2+
out_of_bounds="""
3+
>>> import h2o
4+
>>> from h2o import H2OFrame
5+
>>> from h2o.estimators.isotonicregression import H2OIsotonicRegressionEstimator
6+
>>> from sklearn.datasets import make_regression
7+
>>> import numpy as np
8+
>>> h2o.init()
9+
>>> X, y = make_regression(n_samples=10000, n_features=1, random_state=41, noise=0.8)
10+
>>> X = X.reshape(-1)
11+
>>> train = H2OFrame(np.column_stack((y, X)), column_names=["y", "X"])
12+
>>> w_values = np.random.rand(train.shape[0])
13+
>>> w_frame = H2OFrame(w_values.reshape(-1, 1), column_names=["w"])
14+
>>> train = train.cbind(w_frame)
15+
>>> h2o_iso_reg = H2OIsotonicRegressionEstimator(out_of_bounds="clip")
16+
>>> h2o_iso_reg.train(training_frame=train, x="X", y="y")
17+
>>> h2o_iso_reg.predict(train)
18+
"""
19+
)

h2o-py/h2o/estimators/isotonicregression.py

+18
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,24 @@ def out_of_bounds(self):
184184
Method of handling values of X predictor that are outside of the bounds seen in training.
185185
186186
Type: ``Literal["na", "clip"]``, defaults to ``"na"``.
187+
188+
:examples:
189+
190+
>>> import h2o
191+
>>> from h2o import H2OFrame
192+
>>> from h2o.estimators.isotonicregression import H2OIsotonicRegressionEstimator
193+
>>> from sklearn.datasets import make_regression
194+
>>> import numpy as np
195+
>>> h2o.init()
196+
>>> X, y = make_regression(n_samples=10000, n_features=1, random_state=41, noise=0.8)
197+
>>> X = X.reshape(-1)
198+
>>> train = H2OFrame(np.column_stack((y, X)), column_names=["y", "X"])
199+
>>> w_values = np.random.rand(train.shape[0])
200+
>>> w_frame = H2OFrame(w_values.reshape(-1, 1), column_names=["w"])
201+
>>> train = train.cbind(w_frame)
202+
>>> h2o_iso_reg = H2OIsotonicRegressionEstimator(out_of_bounds="clip")
203+
>>> h2o_iso_reg.train(training_frame=train, x="X", y="y")
204+
>>> h2o_iso_reg.predict(train)
187205
"""
188206
return self._parms.get("out_of_bounds")
189207

0 commit comments

Comments
 (0)