Sometime you may want to emulate hierarchical modeling to achieve your objective you can use beta_constraints as below:

iris = h2o.import_file("http://h2o-public-test-data.s3.amazonaws.com/smalldata/iris/iris_wheader.csv") bc = h2o.H2OFrame([("Intercept",-1000,1000,3,30)], column_names=["names","lower_bounds","upper_bounds","beta_given","rho"]) glm = H2OGeneralizedLinearEstimator(family = "gaussian", beta_constraints=bc, standardize=False) glm.coef()

The output will look like as below:

{u'Intercept': 3.000933645168297, u'class.Iris-setosa': 0.0, u'class.Iris-versicolor': 0.0, u'class.Iris-virginica': 0.0, u'petal_len': 0.4423526962303227, u'petal_wid': 0.0, u'sepal_wid': 0.37712042938039897}

There’s more information in the GLM booklet linked below, but the short version is to create a new constraints frame with the columns: names, lower_bounds, upper_bounds, beta_given, & rho, and have a row entry per feature you want to constrain. You can use “Intercept” as a keyword to constraint the intercept.

http://docs.h2o.ai/h2o/latest-stable/h2o-docs/booklets/GLMBooklet.pdf names: (mandatory) coefficient names lower bounds: (optional) coefficient lower bounds , must be less thanor equal to upper bounds upper bounds: (optional) coefficient upper bounds , must be greaterthan or equal to lower bounds beta given: (optional) specifies the given solution in proximal operatorinterface rho (mandatory if beta given is specified, otherwise ignored): specifiesper-column L2 penalties on the distance from the given solution

If you want to go deeper to learn how these L1/L2 parameters works, here are more details:

What’s happening is an L2 penalty is being applied between the coeffecient & given. The proximal penalty is computed: Σ(x-x’)*rho. You can confirm this by setting rho to be whatever lambda may be, and set let lambda to 0. This will give the same result as having set lambda to that value.

You can use beta constraints to assign per-feature regularization strength

but only for l2 penalty. The math is explained here:

sum_i rho[i] * L2norm2(beta[i]-betagiven[i])

So if you set beta given to zero, and say all rho except for the intercept to 1e-5

then it is equivalent to running without BC, just with alpha = 0, lambda = 1e-5

Thats it, enjoy!!

Advertisements
(function(g,$){if("undefined"!=typeof g.__ATA){
g.__ATA.initAd({collapseEmpty:'after', sectionId:26942, width:300, height:250});
g.__ATA.initAd({collapseEmpty:'after', sectionId:114160, width:300, height:250});
}})(window,jQuery);
var o = document.getElementById('crt-300634945');
if ("undefined"!=typeof Criteo) {
var p = o.parentNode;
p.style.setProperty('display', 'inline-block', 'important');
o.style.setProperty('display', 'block', 'important');
Criteo.DisplayAcceptableAdIfAdblocked({zoneid:388248,containerid:"crt-300634945",collapseContainerIfNotAdblocked:true,"callifnotadblocked": function () {var o = document.getElementById('crt-300634945'); o.style.setProperty('display','none','important');o.style.setProperty('visbility','hidden','important'); } });
} else {
o.style.setProperty('display', 'none', 'important');
o.style.setProperty('visibility', 'hidden', 'important');
}
var o = document.getElementById('crt-1888367076');
if ("undefined"!=typeof Criteo) {
var p = o.parentNode;
p.style.setProperty('display', 'inline-block', 'important');
o.style.setProperty('display', 'block', 'important');
Criteo.DisplayAcceptableAdIfAdblocked({zoneid:837497,containerid:"crt-1888367076",collapseContainerIfNotAdblocked:true,"callifnotadblocked": function () {var o = document.getElementById('crt-1888367076'); o.style.setProperty('display','none','important');o.style.setProperty('visbility','hidden','important'); } });
} else {
o.style.setProperty('display', 'none', 'important');
o.style.setProperty('visibility', 'hidden', 'important');
}