Skip to content

Commit 3471612

Browse files
committed
Implement copilot review suggestions
1 parent cca14f4 commit 3471612

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

h2o-algos/src/main/java/hex/glm/GLM.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4109,11 +4109,16 @@ protected void updateProgress(boolean canScore) {
41094109
_scoringHistory.addIterationScore(_state._iter, task._likelihood, objectiveControlVal);
41104110
} else if (_model._parms._remove_offset_effects) {
41114111
_scoringHistoryUnrestrictedModel.addIterationScore(_state._iter, _state.likelihood(), _state.objective());
4112-
Frame frameWithoutOffset = _state._dinfo._adaptedFrame.deepCopy("frWithoutOffsetForScoringOnly");
4113-
Vec offset = frameWithoutOffset.remove(_model._parms._offset_column);
4114-
GLMResDevTask task = new GLMResDevTask(_job._key,_dinfo,_parms, _model.beta()).doAll(frameWithoutOffset);
4115-
offset.remove();
4116-
frameWithoutOffset.remove();
4112+
Frame frameZeroOffset = _state._dinfo._adaptedFrame.deepCopy("frWithoutOffsetForScoringOnly");
4113+
int offsetIdx = frameZeroOffset.find(_model._parms._offset_column);
4114+
assert offsetIdx > -1;
4115+
Vec originalOffset = frameZeroOffset.vec(offsetIdx);
4116+
Vec zeroOffset = originalOffset.makeZero();
4117+
frameZeroOffset.replace(offsetIdx, zeroOffset).remove();
4118+
GLMResDevTask task = new GLMResDevTask(_job._key,_dinfo,_parms, _model.beta()).doAll(frameZeroOffset);
4119+
originalOffset.remove();
4120+
zeroOffset.remove();
4121+
frameZeroOffset.remove();
41174122
double objectiveOffset = _state.objective(_model.beta(), task._likelihood);
41184123
_scoringHistory.addIterationScore(_state._iter, task._likelihood, objectiveOffset);
41194124
} else {

h2o-docs/src/product/data-science/algo-params/control_variables.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ To get the unrestricted model with its own metrics use ``glm.make_unrestricted_g
2121

2222
The control variables' coefficients are set to zero in the variable importance table. Use the unrestricted model to get the variable importance table with all variables included.
2323

24-
If you set up the ``control_variables`` together with the ``remove_offset_effects`` feature, model metrics and scoring history are calculated with both effects enabled.
25-
If you need to get a model with only one feature enabled, you can get it using ``glm.make_derived_glm_model(remove_control_variables_effects=True)`` or ``glm.make_derived_glm_model(remove_offset_effects=True)``
26-
If both features are enabled and ``score_each_iteration=True`` or ``generate_scoring_history=True``, the training the model with big data can be slowed down. The complexity is four times higher than the standard GLM metric calculation.
24+
If you set up the ``control_variables`` together with the ``remove_offset_effects`` feature, model metrics and scoring history are calculated with both features enabled (that is, with both offset and control-variable effects removed during scoring).
25+
If you need to get a model with only one feature enabled, you can get it using ``glm.make_derived_glm_model(remove_control_variables_effects=True)`` or ``glm.make_derived_glm_model(remove_offset_effects=True)``.
26+
If both features are enabled and ``score_each_iteration=True`` or ``generate_scoring_history=True``, training the model on big data can be slowed down. The complexity is four times higher than the standard GLM metric calculation.
2727

2828
**Notes**:
2929

h2o-docs/src/product/data-science/algo-params/remove_offset_effects.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Model metrics and scoring history are calculated for both the restricted model (
1313

1414
To get the unrestricted model with its own metrics use ``glm.make_unrestricted_glm_model()`` / ``h2o.make_unrestricted_glm_model(glm)``.
1515

16-
If you set up the ``remove_offset_effects`` together with the ``control_variables`` feature, model metrics and scoring history are calculated with both effects enabled.
17-
If you need to get a model with only one feature enabled, you can get it using ``glm.make_derived_glm_model(remove_control_variables_effects=True)`` or ``glm.make_derived_glm_model(remove_offset_effects=True)``
18-
If both features are enabled and ``score_each_iteration=True`` or ``generate_scoring_history=True``, the training the model with big data can be slowed down. The complexity is four times higher than the standard GLM metric calculation.
16+
If you set up the ``remove_offset_effects`` together with the ``control_variables`` model metrics and scoring history are calculated with both features enabled (that is, with both offset and control-variable effects removed during scoring).
17+
If you need to get a model with only one feature enabled, you can get it using ``glm.make_derived_glm_model(remove_control_variables_effects=True)`` or ``glm.make_derived_glm_model(remove_offset_effects=True)``.
18+
If both features are enabled and ``score_each_iteration=True`` or ``generate_scoring_history=True``, training the model on big data can be slowed down. The complexity is four times higher than the standard GLM metric calculation.
1919

2020
**Notes**:
2121

h2o-py/tests/testdir_algos/glm/pyunit_glm_control_variables_grid_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def glm_grid_search_control_variables():
2424
train['wt_100'] = (train['CAPSULE'] == "1").ifelse(100, 1)
2525

2626
hyper_parameters = OrderedDict()
27-
hyper_parameters["control_variables"] = [["wt_2"], [["wt_100"]]]
27+
hyper_parameters["control_variables"] = [["wt_2"], ["wt_100"]]
2828
print("GLM grid with the following hyper_parameters:", hyper_parameters)
2929

3030
gs = H2OGridSearch(H2OGeneralizedLinearEstimator, hyper_params=hyper_parameters)

0 commit comments

Comments
 (0)