Example #1
0
def compute_bench(alpha, n_samples, n_features):

    lasso_results = []
    larslasso_results = []
    larslasso_gram_results = []

    n_tests = 1000
    it = 0

    for ns in n_samples:
        for nf in n_features:
            it += 1
            print '=================='
            print 'Iteration %s of %s' % (it, max(len(n_samples), len(n_features)))
            print '=================='
            k = nf // 10
            X, Y, X_test, Y_test, coef_ = make_data(
                n_samples=ns, n_tests=n_tests, n_features=nf,
                noise=0.1, k=k)

            X /= np.sqrt(np.sum(X**2, axis=0)) # Normalize data

            gc.collect()
            print "benching Lasso: "
            clf = Lasso(alpha=alpha, fit_intercept=False)
            tstart = time()
            clf.fit(X, Y)
            lasso_results.append(time() - tstart)

            gc.collect()
            print "benching LassoLARS: "
            clf = LassoLARS(alpha=alpha, fit_intercept=False)
            tstart = time()
            clf.fit(X, Y, normalize=False, precompute=False)
            larslasso_results.append(time() - tstart)

            gc.collect()
            print "benching LassoLARS (precomp. Gram): "
            clf = LassoLARS(alpha=alpha, fit_intercept=False)
            tstart = time()
            clf.fit(X, Y, normalize=False, precompute=True)
            larslasso_gram_results.append(time() - tstart)

    return lasso_results, larslasso_results, larslasso_gram_results
Example #2
0
def compute_bench(alpha, n_samples, n_features):

    def LassoFactory(alpha):
        return Lasso(alpha=alpha, fit_intercept=False)

    def LassoLARSFactory(alpha):
        return LassoLARS(alpha=alpha, fit_intercept=False, normalize=False)

    lasso_results = []
    larslasso_results = []
    larslasso_gram_results = []

    n_tests = 1000
    it = 0

    for ns in n_samples:
        for nf in n_features:
            it += 1
            print '=================='
            print 'Iteration %s of %s' % (it, max(len(n_samples), len(n_features)))
            print '=================='
            k = nf // 10
            X, Y, X_test, Y_test, coef_ = make_data(
                n_samples=ns, n_tests=n_tests, n_features=nf,
                noise=0.1, k=k)

            X /= np.sqrt(np.sum(X**2, axis=0)) # Normalize data

            print "benching Lasso: "
            lasso_results.append(bench(LassoFactory(alpha),
                                                X, Y, X_test, Y_test))
            print "benching LassoLARS: "
            larslasso_results.append(bench(LassoLARSFactory(alpha),
                                                X, Y, X_test, Y_test))
            print "benching LassoLARS (precomp. Gram): "
            Gram = np.dot(X.T, X)
            larslasso_gram_results.append(bench(LassoLARSFactory(alpha),
                                        X, Y, X_test, Y_test, Gram=Gram))

    return lasso_results, larslasso_results, larslasso_gram_results