Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/rel-3.42.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
h2o-ops committed Jul 21, 2023
2 parents c2f3ee2 + 7a59453 commit 3f060b6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
6 changes: 3 additions & 3 deletions h2o-docs/src/product/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

# General information about the project.
project = u'H2O'
copyright = u'2016-2022 H2O.ai'
copyright = u'2016-2023 H2O.ai'
author = u'h2o'

# The version info for the project you're documenting, acts as replacement for
Expand All @@ -85,14 +85,14 @@
# the code sample.
substitutions = [
# variable for H2O-3 version
('|version|', '3.38.0.2')
('|version|', '3.42.0.2')
]

# Substitutions for variables in text. Such as when the
# paragraph says, "change to the |version| folder".
# Note that this will not work with formatted (i.e, bolded) text.
rst_prolog = """
.. |version| replace:: 3.38.0.2
.. |version| replace:: 3.42.0.2
"""

# The language for content autogenerated by Sphinx. Refer to documentation
Expand Down
Binary file modified h2o-docs/src/product/images/aucpr_curve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion h2o-py/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

# General information about the project.
project = 'H2O'
copyright = '2015-2022 H2O.ai'
copyright = '2015-2023 H2O.ai'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down
31 changes: 27 additions & 4 deletions h2o-py/h2o/model/metrics/binomial.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,29 @@ def recall(self, thresholds=None):
"""
return self.metric("recall", thresholds=thresholds)

def precision(self, thresholds=None):
"""
:param thresholds: thresholds parameter must be a list (e.g. ``[0.01, 0.5, 0.99]``).
If None, then the threshold maximizing the metric will be used.
:returns: Precision for this set of metrics and thresholds.
:examples:
>>> from h2o.estimators.gbm import H2OGradientBoostingEstimator
>>> cars = h2o.import_file("https://s3.amazonaws.com/h2o-public-test-data/smalldata/junit/cars_20mpg.csv")
>>> cars["economy_20mpg"] = cars["economy_20mpg"].asfactor()
>>> predictors = ["displacement","power","weight","acceleration","year"]
>>> response = "economy_20mpg"
>>> train, valid = cars.split_frame(ratios = [.8], seed = 1234)
>>> cars_gbm = H2OGradientBoostingEstimator(seed = 1234)
>>> cars_gbm.train(x = predictors,
... y = response,
... training_frame = train,
... validation_frame = valid)
>>> cars_gbm.precision()
"""
return self.metric("precision", thresholds=thresholds)

def sensitivity(self, thresholds=None):
"""
:param thresholds: thresholds parameter must be a list (e.g. ``[0.01, 0.5, 0.99]``).
Expand Down Expand Up @@ -571,16 +594,16 @@ def _plot_roc(self, server=False, save_to_file=None, plot=True):
return decorate_plot_result(res=(self.fprs, self.tprs))

def _plot_pr(self, server=False, save_to_file=None, plot=True):
recalls = [x[0] for x in self.recall(thresholds='all')]
precisions = self.tprs
recalls = self.tprs
precisions = [x[1] for x in self.precision(thresholds='all')]
assert len(precisions) == len(recalls), "Precision and recall arrays must have the same length"
if plot:
plt = get_matplotlib_pyplot(server)
if plt is None:
return decorate_plot_result(figure=RAISE_ON_FIGURE_ACCESS)
fig = plt.figure()
plt.xlabel('Recall (TP/(TP+FP))')
plt.ylabel('Precision (TPR)')
plt.xlabel('Recall (TP/(TP+FN))')
plt.ylabel('Precision (TP/(TP+FP)')
plt.title('Precision Recall Curve')
plt.text(0.75, 0.95, r'auc_pr={0:.4f}'.format(self._metric_json["pr_auc"]))
plt.plot(recalls, precisions, 'b--')
Expand Down

0 comments on commit 3f060b6

Please sign in to comment.