Esempio n. 1
0
def lasso_model_walk(X, Y, B=None, nr_steps=64, start=None, step=.9, tol=None, return_lams=False):
    Y, mean = center(Y, axis=1)
    Bs,lams = lasso_walk(X,Y, B, nr_steps, start, step, tol, return_lams=True)
    models = [lasso_model(B, mean) for B in Bs]
    if return_lams:
        return models, lams
    return models
Esempio n. 2
0
def lasso_model_walk(X, Y, B=None, nr_steps=64, start=None, step=.9, tol=None, return_lams=False):
    Y, mean = center(Y, axis=1)
    Bs,lams = lasso_walk(X,Y, B, nr_steps, start, step, tol, return_lams=True)
    models = [lasso_model(B, mean) for B in Bs]
    if return_lams:
        return models, lams
    return models
Esempio n. 3
0
 def retrain(self, features, labels, lam, **kwargs):
     features, mean = center(features)
     betas = lasso(features,
                   labels,
                   self.betas.copy(),
                   lam=lam,
                   **_dict_subset(kwargs, ['tol', 'max_iter']))
     return lasso_model(betas, mean)
Esempio n. 4
0
 def evaluate(lam):
     predicted = []
     for i in xrange(0,len(labels),3):
         idx = np.ones(len(labels), bool)
         idx[i:i+3] = 0
         Y, Ymean = center(labels[idx].T, axis=1)
         B,err = best_B(i,lam)
         if err > 0:
             B = lasso(features[idx].T, Y, B, lam=lam, tol=1e-3)
         model = lasso_model(B, Ymean)
         predicted.append(model.apply(features[i].T))
         try:
             predicted.append(model.apply(features[i+1]))
             predicted.append(model.apply(features[i+2]))
         except IndexError:
             pass
         models[i][lam] = B
     predicted = np.array(predicted)
     cur = 0.0
     for p,ell in zip(predicted.T, labels.T):
         corr,ps = spearnan_compare(p, ell)
         cur += corr
     print('evaluate({0}) = {1:.2%}'.format(lam, cur/labels.shape[1]))
     return - cur / labels.shape[1]
Esempio n. 5
0
 def train(self, features, labels, betas=None, **kwargs):
     labels, mean = center(labels, axis=1) 
     betas = lasso(features, labels, betas, lam=self.lam)
     return lasso_model(betas, mean)
Esempio n. 6
0
 def train(self, features, labels, betas=None, **kwargs):
     labels, mean = center(labels, axis=1)
     betas = lasso(features, labels, betas, lam=self.lam)
     return lasso_model(betas, mean)
Esempio n. 7
0
 def retrain(self, features, labels, lam, **kwargs):
     features, mean = center(features)
     betas = lasso(features, labels, self.betas.copy(), lam=lam, **_dict_subset(kwargs, ['tol', 'max_iter']))
     return lasso_model(betas, mean)
Esempio n. 8
0
 def train(self, features, labels):
     from milk.unsupervised import center
     labels, mean = center(labels, axis=self.axis)
     return self.base.train(features, labels)