# Ticket #1118: lasso_lbfgs.diff

File lasso_lbfgs.diff, 1.4 KB (added by lanz, 2 years ago)

Another optimization function. Note that the parameter t here is not the same as before.

• ## Orange/regression/lasso.py

`diff --git a/Orange/regression/lasso.py b/Orange/regression/lasso.py`
 a """ def __init__(self, name='lasso regression', t=1, s=None, tol=0.001, \ n_boot=100, n_perm=100, imputer=None, continuizer=None): n_boot=0, n_perm=0, imputer=None, continuizer=None): """ :param name: name of the linear model, default 'lasso regression' :type name: string import scipy.optimize # objective function to be minimized objective = lambda beta: numpy.linalg.norm(y - numpy.dot(X, beta)) objective = lambda beta: (numpy.sum((y - numpy.dot(X, beta)) ** 2) + t * numpy.linalg.norm(beta, 1)) # initial guess for the regression parameters beta_init = numpy.random.random(m) # constraints for the regression coefficients cnstr = lambda beta: t - numpy.sum(numpy.abs(beta)) beta_init = numpy.zeros(m) # optimal solution coefficients = scipy.optimize.fmin_cobyla(objective, beta_init, cnstr, iprint=0) coefficients, val, _ = scipy.optimize.fmin_l_bfgs_b(objective, beta_init, approx_grad=1, disp=0) # set small coefficients to 0 def set_2_0(c): return c if abs(c) > self.tol else 0 coefficients = numpy.array(map(set_2_0, coefficients))