Beispiel #1
0
def fun(nGPUs=1, nFolds=1, nLambdas=100, nAlphas=8, validFraction=0.2):
    name = str(sys._getframe().f_code.co_name)
    name = sys._getframe(1).f_code.co_name
    t = time.time()

    print("cwd: %s" % (os.getcwd()))
    sys.stdout.flush()

    print("Reading Data")
    #
    df = pd.read_csv("./open_data/simple.txt", delim_whitespace=True)
    print(df.shape)
    X = np.array(df.iloc[:, :df.shape[1] - 1], dtype='float32', order='C')
    y = np.array(df.iloc[:, df.shape[1] - 1], dtype='float32', order='C')

    t1 = time.time()
    rmse_train, rmse_test = run_glm(X,
                                    y,
                                    nGPUs=nGPUs,
                                    nlambda=nLambdas,
                                    nfolds=nFolds,
                                    nalpha=nAlphas,
                                    validFraction=validFraction,
                                    verbose=0,
                                    name=name,
                                    solver="ridge")

    # check rmse
    print(rmse_train[0, 0])
    print(rmse_train[0, 1])
    print(rmse_train[0, 2])
    print(rmse_test[0, 2])
    sys.stdout.flush()

    if validFraction == 0.0:
        assert rmse_train[0, 0] < 54000
        assert rmse_train[0, 1] < 54000
        assert rmse_train[0, 2] < 54000
        assert rmse_test[0, 2] < 54000
    else:
        if nLambdas > 20:
            assert rmse_train[0, 0] < 50000
            assert rmse_train[0, 1] < 50000
            assert rmse_train[0, 2] < 50000
            assert rmse_test[0, 2] < 50000
        else:
            assert rmse_train[0, 0] < 59000
            assert rmse_train[0, 1] < 59000
            assert rmse_train[0, 2] < 59000
            assert rmse_test[0, 2] < 59000

    print('/n Total execution time:%d' % (time.time() - t1))

    print("TEST PASSED")
    sys.stdout.flush()

    print("Time taken: {}".format(time.time() - t))
    #    endfunnel(pipes)
    print("DONE.")
    sys.stdout.flush()
Beispiel #2
0
def fun(nGPUs=1, nFolds=1, nLambdas=100, nAlphas=8, validFraction=0.2):
    name = str(sys._getframe().f_code.co_name)
    name = sys._getframe(1).f_code.co_name
    t = time.time()

    print("cwd: %s" % (os.getcwd()))
    sys.stdout.flush()


    print("Reading Data")
    #
    df = pd.read_csv("./open_data/simple.txt", delim_whitespace=True)
    print(df.shape)
    X = np.array(df.iloc[:, :df.shape[1] - 1], dtype='float32', order='C')
    y = np.array(df.iloc[:, df.shape[1] - 1], dtype='float32', order='C')

    t1 = time.time()
    rmse_train, rmse_test = run_glm(X, y, nGPUs=nGPUs, nlambda=nLambdas, nfolds=nFolds, nalpha=nAlphas,
                                        validFraction=validFraction, verbose=0, name=name, solver="ridge")

    # check rmse
    print(rmse_train[0, 0])
    print(rmse_train[0, 1])
    print(rmse_train[0, 2])
    print(rmse_test[0, 2])
    sys.stdout.flush()

    if validFraction==0.0:
        assert rmse_train[0, 0] < 54000
        assert rmse_train[0, 1] < 54000
        assert rmse_train[0, 2] < 54000
        assert rmse_test[0, 2] < 54000
    else:
        if nLambdas>20:
            assert rmse_train[0, 0] < 50000
            assert rmse_train[0, 1] < 50000
            assert rmse_train[0, 2] < 50000
            assert rmse_test[0, 2] < 50000
        else:
            assert rmse_train[0, 0] < 59000
            assert rmse_train[0, 1] < 59000
            assert rmse_train[0, 2] < 59000
            assert rmse_test[0, 2] < 59000

    print('/n Total execution time:%d' % (time.time() - t1))

    print("TEST PASSED")
    sys.stdout.flush()

    print("Time taken: {}".format(time.time() - t))
    #    endfunnel(pipes)
    print("DONE.")
    sys.stdout.flush()
Beispiel #3
0
def fun(nGPUs=1, nFolds=1, nLambdas=100, nAlphas=8, validFraction=0.2):
    name = str(sys._getframe().f_code.co_name)
    name = sys._getframe(1).f_code.co_name
    t = time.time()

    print("cwd: %s" % (os.getcwd()))
    sys.stdout.flush()

    print("Reading Data")
    # from numpy.random import randn
    #  m=1000
    #  n=100
    #  A=randn(m,n)
    #  x_true=(randn(n)/n)*float64(randn(n)<0.8)
    #  b=A.dot(x_true)+0.5*randn(m)

    # Rscript ipums.R  runs glmnet on ipums
    #
    df = pd.read_csv("./data/ipums_1k.csv")
    print(df.shape)
    X = np.array(df.iloc[:, :df.shape[1] - 1], dtype='float32', order='C')
    y = np.array(df.iloc[:, df.shape[1] - 1], dtype='float32', order='C')
    #X = df.iloc[:, :df.shape[1] - 1]
    #y = df.iloc[:, df.shape[1] - 1]

    t1 = time.time()
    # by default, tol=1E-2 for h2o4gpu and don't try to be strictly as accurate as h2o-3, so use tolernace that represents how well we expect to do with default tol for glm algo.
    rmse_train, rmse_test = run_glm(X,
                                    y,
                                    nGPUs=nGPUs,
                                    nlambda=nLambdas,
                                    nfolds=nFolds,
                                    nalpha=nAlphas,
                                    validFraction=validFraction,
                                    verbose=0,
                                    name=name,
                                    tolerance=0.34)

    # check rmse
    print(rmse_train[0, 0])
    print(rmse_train[0, 1])
    print(rmse_train[0, 2])
    print(rmse_test[0, 2])
    sys.stdout.flush()

    if validFraction == 0.0:
        assert rmse_train[0, 0] < 54000
        assert rmse_train[0, 1] < 54000
        assert rmse_train[0, 2] < 54000
        assert rmse_test[0, 2] < 54000
    else:
        if nLambdas > 20:
            assert rmse_train[0, 0] < 50000
            assert rmse_train[0, 1] < 50000
            assert rmse_train[0, 2] < 50000
            assert rmse_test[0, 2] < 50000
        else:
            assert rmse_train[0, 0] < 59000
            assert rmse_train[0, 1] < 59000
            assert rmse_train[0, 2] < 59000
            assert rmse_test[0, 2] < 59000

    print('/n Total execution time:%d' % (time.time() - t1))

    print("TEST PASSED")
    sys.stdout.flush()

    print("Time taken: {}".format(time.time() - t))
    #    endfunnel(pipes)
    print("DONE.")
    sys.stdout.flush()
Beispiel #4
0
def func(nGPUs=1, nFolds=1, nLambdas=100, nAlphas=8, validFraction=0.2, verbose=0, family="elasticnet",
         print_all_errors=False, tolerance=.1):
    name = str(sys._getframe().f_code.co_name)
    name = str(sys._getframe(1).f_code.co_name)
    t = time.time()

    print("cwd: %s" % (os.getcwd()))
    sys.stdout.flush()

    print("Reading Data")
    df = pd.read_csv("./open_data/creditcard.csv")
    print(df.shape)
    X = np.array(df.iloc[:, :df.shape[1] - 1], dtype='float32', order='C')
    y = np.array(df.iloc[:, df.shape[1] - 1], dtype='float32', order='C')

    t1 = time.time()

    logloss_train, logloss_test = run_glm(X, y, nGPUs=nGPUs, nlambda=nLambdas, nfolds=nFolds, nalpha=nAlphas,
                                          validFraction=validFraction, verbose=verbose,print_all_errors=print_all_errors,
                                          tolerance=tolerance, name=name, solver="glm", family = "logistic")

    # check logloss
    print(logloss_train[0, 0])
    print(logloss_train[0, 1])
    print(logloss_train[0, 2])
    print(logloss_test[0, 2])
    sys.stdout.flush()

    # Train only
    if validFraction == 0.0 and nFolds == 0:
        assert logloss_train[0, 0] < .47
        assert logloss_train[1, 0] < .47
        assert logloss_train[2, 0] < .47
        assert logloss_test[0, 0] < .47
        assert logloss_test[1, 0] < .47
        assert logloss_test[2, 0] < .47

    # Train + nfolds
    if validFraction == 0.0 and nFolds > 0:
        assert logloss_train[0, 0] < .48
        assert logloss_train[0, 1] < .44
        assert logloss_train[1, 0] < .48
        assert logloss_train[1, 1] < .48
        assert logloss_train[2, 0] < .48
        assert logloss_train[2, 1] < .44
        assert logloss_test[0, 0] < .48
        assert logloss_test[0, 1] < .44
        assert logloss_test[1, 0] < .48
        assert logloss_test[1, 1] < .48
        assert logloss_test[2, 0] < .48
        assert logloss_test[2, 1] < .44

    # Train + validation
    if validFraction > 0.0 and nFolds == 0:
        assert logloss_train[0, 0] < .48
        assert logloss_train[0, 2] < .44
        assert logloss_train[1, 0] < .48
        assert logloss_train[1, 2] < .44
        assert logloss_train[2, 0] < .48
        assert logloss_train[2, 2] < .44
        assert logloss_test[0, 0] < .48
        assert logloss_test[0, 2] < .44
        assert logloss_test[1, 0] < .48
        assert logloss_test[1, 2] < .44
        assert logloss_test[2, 0] < .48
        assert logloss_test[2, 2] < .44

    # Train + validation + nfolds
    if validFraction > 0.0 and nFolds > 0:
        assert logloss_train[0, 0] < .48
        assert logloss_train[0, 1] < .48
        assert logloss_train[0, 2] < .44
        assert logloss_train[1, 0] < .48
        assert logloss_train[1, 1] < .48
        assert logloss_train[1, 2] < .44
        assert logloss_train[2, 0] < .48
        assert logloss_train[2, 1] < .48
        assert logloss_train[2, 2] < .44
        assert logloss_test[0, 0] < .48
        assert logloss_test[0, 1] < .48
        assert logloss_test[0, 2] < .44
        assert logloss_test[1, 0] < .48
        assert logloss_test[1, 1] < .48
        assert logloss_test[1, 2] < .44
        assert logloss_test[2, 0] < .48
        assert logloss_test[2, 1] < .48
        assert logloss_test[2, 2] < .44

    sys.stdout.flush()

    print('/n Total execution time:%d' % (time.time() - t1))

    print("TEST PASSED")
    sys.stdout.flush()

    print("Time taken: {}".format(time.time() - t))

    print("DONE.")
    sys.stdout.flush()
Beispiel #5
0
    def fun(nGPUs=1,
            nFolds=1,
            nLambdas=100,
            nAlphas=8,
            validFraction=0.2,
            whichdata=0,
            double_precision=False):
        name = str(sys._getframe().f_code.co_name)
        t = time.time()

        print("cwd: %s" % (os.getcwd()))
        sys.stdout.flush()

        name = sys._getframe(1).f_code.co_name
        #    pipes = startfunnel(os.path.join(os.getcwd(), "tmp/"), name)

        print("Getting Data")
        from h2o4gpu.datasets import fetch_20newsgroups, fetch_20newsgroups_vectorized, fetch_california_housing, \
            fetch_covtype, fetch_kddcup99, fetch_lfw_pairs, fetch_lfw_people, fetch_mldata, fetch_olivetti_faces, \
            fetch_rcv1, fetch_species_distributions
        from h2o4gpu.model_selection import train_test_split

        # Fetch dataset
        if whichdata == 0:
            data = fetch_20newsgroups()  # runs
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 1:
            data = fetch_20newsgroups_vectorized()  # sparse
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 2:
            data = fetch_california_housing()  # runs
            sizetokeep = 1000
        elif whichdata == 3:
            data = fetch_covtype()
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 4:
            data = fetch_kddcup99()  # strings -> numeric
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 5:
            data = fetch_lfw_pairs()
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 6:
            data = fetch_lfw_people()
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 7:
            data = fetch_mldata('iris')
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 8:
            data = fetch_mldata('leukemia')  # runs
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 9:
            data = fetch_mldata('Whistler Daily Snowfall')
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 10:
            data = fetch_olivetti_faces()  # runs
            sizetokeep = 100
        elif whichdata == 11:
            data = fetch_rcv1()
            sizetokeep = 1000  # 1k rows for now
            # data = data.todense() # FIXME: glm and kmeans h2o4gpu currently only supports dense matrices
        elif whichdata == 12:
            data = fetch_species_distributions()
            sizetokeep = 1000  # 1k rows for now
        else:
            ValueError("No such whichdata")

        try:
            sizetokeep = min(sizetokeep, len(data.data[:, 0]))
            X = data.data[0:sizetokeep, :]
        except:
            sizetokeep = min(sizetokeep, len(data.data[:]))
            X = data.data[0:sizetokeep]
        y = data.target[0:sizetokeep]
        print("Got Data")

        import numpy as np

        # Create 0.8/0.2 train/test split
        print("Split Data")
        X_train, X_test, y_train, y_test = train_test_split(X,
                                                            y,
                                                            test_size=0.2,
                                                            train_size=0.8,
                                                            random_state=42)

        print("Encode Data")
        # from h2o4gpu.preprocessing import Imputer
        # imp = Imputer(missing_values='NaN', strategy='mean', axis=0)
        # imp.fit(X, y)
        # Xencoded = imp.transform(X)
        # yencoded = imp.transform(y)

        import pandas as pd
        X_test_pd = pd.DataFrame(X_test)
        X_train_pd = pd.DataFrame(X_train)

        # Importing LabelEncoder and initializing it
        from h2o4gpu.preprocessing import LabelEncoder
        le = LabelEncoder()
        # Iterating over all the common columns in train and test
        for col in X_test_pd.columns.values:
            # Encoding only categorical variables
            if X_test_pd[col].dtypes == 'object' or X_test_pd[
                    col].dtypes == 'bool':
                # Using whole data to form an exhaustive list of levels
                data = X_train_pd[col].append(X_test_pd[col])
                le.fit(data.values)
                X_train_pd[col] = le.transform(X_train_pd[col])
                X_test_pd[col] = le.transform(X_test_pd[col])

        X_train_pd = pd.get_dummies(X_train_pd).fillna(0.0)
        X_test_pd = pd.get_dummies(X_test_pd).fillna(0.0)
        y_train_pd = pd.Series(y_train).fillna(0.0)
        y_test_pd = pd.Series(y_test).fillna(0.0)

        # get back numpy
        X_test = X_test_pd.values
        X_train = X_train_pd.values
        y_test = y_test_pd.values
        y_train = y_train_pd.values

        if double_precision:
            mynptype = np.float64
        else:
            mynptype = np.float32
        X_test = X_test.astype(mynptype)
        X_train = X_train.astype(np.float64)
        y_test = y_test.astype(np.float64)
        y_train = y_train.astype(np.float64)

        # TODO: Should write this to file and avoid doing encoding if already exists

        t1 = time.time()
        print("Start ElasticNetH2O")
        rmse_train, rmse_test = run_glm(X_train,
                                        y_train,
                                        X_test,
                                        y_test,
                                        nGPUs=nGPUs,
                                        nlambda=nLambdas,
                                        nfolds=nFolds,
                                        nalpha=nAlphas,
                                        validFraction=validFraction,
                                        verbose=0,
                                        name=name,
                                        tolerance=0.2,
                                        tol=1E-2,
                                        tol_seek_factor=1.0)
        print("End ElasticNetH2O")

        # check rmse
        print(rmse_train[0, 0])
        print(rmse_train[0, 1])
        print(rmse_train[0, 2])
        print(rmse_test[0, 2])
        sys.stdout.flush()

        print('/n Total execution time:%d' % (time.time() - t1))

        print("TEST PASSED")
        sys.stdout.flush()

        print("Time taken: {}".format(time.time() - t))
        #    endfunnel(pipes)
        print("DONE.")
        sys.stdout.flush()
Beispiel #6
0
def fun(nGPUs=1, nFolds=1, nLambdas=100, nAlphas=8, classification=False, use_seed=True, validFraction=0.0):
    name = str(sys._getframe().f_code.co_name)
    name = str(sys._getframe(1).f_code.co_name)
    t = time.time()

    print("cwd: %s" % (os.getcwd()))
    sys.stdout.flush()

    if nGPUs > 0:
        use_gpu = True
    else:
        use_gpu = False

    display = 1
    write = 1

    # seed = np.random.randint(0, 2 ** 31 - 1)
    seed = 1034753 if use_seed else None

    print("Reading Data")
    if 1 == 0:  # not yet
        t1 = time.time()
        target = None
        import datatable as dt  # omp problem in pycharm
        train = find_file("xtrain_1k.txt")
        test = find_file("xtest_1k.txt")

        train = os.path.normpath(os.path.join(os.getcwd(), train))
        train_df = dt.fread(train).topandas()
        train_df = train_df[pd.notnull(train_df[target])].reset_index(drop=True)  # drop rows with NA response

        test = os.path.normpath(os.path.join(os.getcwd(), test))
        test_df = dt.fread(test).topandas()
        test_df = test_df[pd.notnull(test_df[target])].reset_index(drop=True)  # drop rows with NA response

        y = train_df[target]

        df_before = copy.deepcopy(train_df)

        classes = 1 if not classification else len(y.unique())
        print("Testing GLM for " + ((str(classes) + "-class classification") if classes >= 2 else "regression"))
    else:
        if 1 == 0:  # avoid for now so get info
            # should all be explicitly np.float32 or all np.float64
            xtrain = np.loadtxt("./data/xtrainhyatt_1k.csv", delimiter=',', dtype=np.float32)
            ytrain = np.loadtxt("./data/ytrainhyatt_1k.csv", delimiter=',', dtype=np.float32)
            xtest = np.loadtxt("./data/xtesthyatt_1k.csv", delimiter=',', dtype=np.float32)
            ytest = np.loadtxt("./data/ytesthyatt_1k.csv", delimiter=',', dtype=np.float32)
            wtrain = np.ones((xtrain.shape[0], 1), dtype=np.float32)

            t1 = time.time()
            pred_val, rmse_train, rmse_test = run_glm_ptr(nFolds, nAlphas, nLambdas, xtrain, ytrain, xtest, ytest, wtrain,
                                                     write, display, use_gpu)
        else:
            # should all be explicitly np.float32 or all np.float64
            xfull = np.loadtxt("./data/xfullhyatt_2k.csv", delimiter=',', dtype=np.float32)
            #xfull = np.asfortranarray(xfull0)
            yfull = np.loadtxt("./data/yfullhyatt_2k.csv", delimiter=',', dtype=np.float32)

            t1 = time.time()
            rmse_train, rmse_test = run_glm(xfull, yfull, nGPUs=nGPUs, nlambda=nLambdas, nfolds=nFolds,
                                                nalpha=nAlphas,
                                                validFraction=validFraction, verbose=0, name=name)
        print("Testing GLM")

    # check rmse
    print(rmse_train[-1, 0])
    print(rmse_train[-1, 1])
    print(rmse_train[-1, 2])
    print(rmse_test[-1, 2])
    sys.stdout.flush()

    # FIXME: But these below should really be order 1 to 1.5 according to Wamsi!
    assert rmse_train[-1, 0] < 14
    assert rmse_train[-1, 1] < 14
    assert rmse_train[-1, 2] < 21
    assert rmse_test[-1, 2] < 21

    print('/n Total execution time:%d' % (time.time() - t1))

    print("TEST PASSED")
    sys.stdout.flush()

    print("Time taken: {}".format(time.time() - t))
    #    endfunnel(pipes)
    print("DONE.")
    sys.stdout.flush()
Beispiel #7
0
def fun(nGPUs=1, nFolds=1, nLambdas=100, nAlphas=8, validFraction=0.2, choosealphalambda=None):
    name = str(sys._getframe().f_code.co_name)
    name = str(sys._getframe(1).f_code.co_name)
    t = time.time()

    print("cwd: %s" % (os.getcwd()))
    sys.stdout.flush()

    #    pipes = startfunnel(os.path.join(os.getcwd(), "tmp/"), name)

    print("Reading Data")
    # from numpy.random import randn
    #  m=1000
    #  n=100
    #  A=randn(m,n)
    #  x_true=(randn(n)/n)*float64(randn(n)<0.8)
    #  b=A.dot(x_true)+0.5*randn(m)

    df = pd.read_csv("./open_data/simple.txt", sep=" ", header=None)
    print(df.shape)
    X = np.array(df.iloc[:, :df.shape[1] - 1], dtype='float32', order='C')
    y = np.array(df.iloc[:, df.shape[1] - 1], dtype='float32', order='C')

    if choosealphalambda == 1 or choosealphalambda == 3:
        alphas = [1E-1, 0.3, 0.5, 1.0]
    else:
        alphas = None
    if choosealphalambda == 2 or choosealphalambda == 3:
        lambdas = [2, 1E-2, 1E-3, 1E-5]
    else:
        lambdas = None

    t1 = time.time()
    rmse_train, rmse_test = run_glm(X, y, nGPUs=nGPUs, nlambda=nLambdas, nfolds=nFolds, nalpha=nAlphas,
                                    validFraction=validFraction, verbose=0, name=name, alphas=alphas, lambdas=lambdas, tolerance=0.3)

    # check rmse
    print(rmse_train[0, 0])
    print(rmse_train[0, 1])
    print(rmse_train[0, 2])
    print(rmse_test[0, 2])
    sys.stdout.flush()

    if validFraction == 0.0:
        if nLambdas > 50:
            if nFolds == 1:
                assert rmse_train[0, 0] < 0.04
                assert rmse_train[0, 1] < 0.04
                assert rmse_train[0, 2] < 0.04
                assert rmse_test[0, 2] < 0.04

                assert rmse_train[-1, 0] < 0.05
                assert rmse_train[-1, 1] < 0.05
                assert rmse_train[-1, 2] < 0.05
                assert rmse_test[-1, 2] < 0.05
            else:
                assert rmse_train[0, 0] < 0.37
                assert rmse_train[0, 1] < 0.22
                assert rmse_train[0, 2] < 0.4
                assert rmse_test[0, 2] < 0.4

                assert rmse_train[-1, 0] < 0.37
                assert rmse_train[-1, 1] < 0.77
                assert rmse_train[-1, 2] < 0.4
                assert rmse_test[-1, 2] < 0.4
        else:
            if nFolds == 1:
                assert rmse_train[0, 0] < 0.11
                assert rmse_train[0, 1] < 0.12
                assert rmse_train[0, 2] < 0.1
                assert rmse_test[0, 2] < 0.1

                assert rmse_train[-1, 0] < 0.11
                assert rmse_train[-1, 1] < 0.12
                assert rmse_train[-1, 2] < 0.1
                assert rmse_test[-1, 2] < 0.1
            else:
                assert rmse_train[0, 0] < 0.37
                assert rmse_train[0, 1] < 0.22
                assert rmse_train[0, 2] < 0.4
                assert rmse_test[0, 2] < 0.4

                assert rmse_train[-1, 0] < 0.37
                assert rmse_train[-1, 1] < 0.24
                assert rmse_train[-1, 2] < 0.4
                assert rmse_test[-1, 2] < 0.4
    else:
        if nLambdas > 50:
            if nFolds == 1:
                assert rmse_train[0, 0] < 0.4
                assert rmse_train[0, 1] < 0.4
                assert rmse_train[0, 2] < 0.51
                assert rmse_test[0, 2] < 0.51

                assert rmse_train[-1, 0] < 0.51
                assert rmse_train[-1, 1] < 0.51
                assert rmse_train[-1, 2] < 0.51
                assert rmse_test[-1, 2] < 0.51
            else:
                assert rmse_train[0, 0] < 0.51
                assert rmse_train[0, 1] < 0.51
                assert rmse_train[0, 2] < 2
                assert rmse_test[0, 2] < 2

                assert rmse_train[-1, 0] < 0.54
                assert rmse_train[-1, 1] < 0.54
                assert rmse_train[-1, 2] < 2.2
                assert rmse_test[-1, 2] < 2.2
        else:
            if nFolds == 1:
                assert rmse_train[0, 0] < 0.4
                assert rmse_train[0, 1] < 0.4
                assert rmse_train[0, 2] < 2
                assert rmse_test[0, 2] < 2

                assert rmse_train[-1, 0] < 0.51
                assert rmse_train[-1, 1] < 0.51
                assert rmse_train[-1, 2] < 2
                assert rmse_test[-1, 2] < 2
            else:
                assert rmse_train[0, 0] < 0.45
                assert rmse_train[0, 1] < 0.3
                assert rmse_train[0, 2] < 2
                assert rmse_test[0, 2] < 2

                assert rmse_train[-1, 0] < 0.45
                assert rmse_train[-1, 1] < 0.3
                assert rmse_train[-1, 2] < 2
                assert rmse_test[-1, 2] < 2

    print('/n Total execution time:%d' % (time.time() - t1))

    print("TEST PASSED")
    sys.stdout.flush()

    print("Time taken: {}".format(time.time() - t))
    #    endfunnel(pipes)
    print("DONE.")
    sys.stdout.flush()
Beispiel #8
0
def fun(nGPUs=1,
        nFolds=1,
        nLambdas=100,
        nAlphas=8,
        validFraction=0.2,
        verbose=0,
        family="elasticnet",
        print_all_errors=False,
        tolerance=.001):
    name = str(sys._getframe().f_code.co_name)
    name = sys._getframe(1).f_code.co_name

    t = time.time()

    print("cwd: %s" % (os.getcwd()))
    sys.stdout.flush()

    print("Reading Data")
    df = feather.read_dataframe("./data/bnp.feather")
    print(df.shape)
    X = np.array(df.iloc[:, :df.shape[1] - 1], dtype='float32', order='C')
    y = np.array(df.iloc[:, df.shape[1] - 1], dtype='float32', order='C')
    print("Y")
    print(y)

    t1 = time.time()

    logloss_train, logloss_test = run_glm(X,
                                          y,
                                          nGPUs=nGPUs,
                                          nlambda=nLambdas,
                                          nfolds=nFolds,
                                          nalpha=nAlphas,
                                          validFraction=validFraction,
                                          verbose=verbose,
                                          family=family,
                                          print_all_errors=print_all_errors,
                                          tolerance=tolerance,
                                          name=name)

    # check logloss
    print(logloss_train[0, 0])
    print(logloss_train[0, 1])
    print(logloss_train[0, 2])
    print(logloss_test[0, 2])
    sys.stdout.flush()

    #Always checking the first 3 alphas with specific logloss scores (.48,.44)
    if validFraction == 0.0 and nFolds > 0:
        assert logloss_train[0, 0] < .49
        assert logloss_train[0, 1] < .49
        assert logloss_train[1, 0] < .52
        assert logloss_train[1, 1] < .52
        assert logloss_train[2, 0] < .49
        assert logloss_train[2, 1] < .49
    if validFraction > 0.0:
        assert logloss_train[0, 0] < .49
        assert logloss_train[0, 1] < .49
        assert logloss_train[0, 2] < .49
        assert logloss_train[1, 0] < .50
        assert logloss_train[1, 1] < .51
        assert logloss_train[1, 2] < .51
        assert logloss_train[2, 0] < .49
        assert logloss_train[2, 1] < .49
        assert logloss_train[2, 2] < .49

    sys.stdout.flush()

    print('/n Total execution time:%d' % (time.time() - t1))

    print("TEST PASSED")
    sys.stdout.flush()

    print("Time taken: {}".format(time.time() - t))

    print("DONE.")
    sys.stdout.flush()
Beispiel #9
0
def fun(nGPUs=1,
        nFolds=1,
        nLambdas=100,
        nAlphas=8,
        validFraction=0.2,
        choosealphalambda=None):
    name = str(sys._getframe().f_code.co_name)
    name = str(sys._getframe(1).f_code.co_name)
    t = time.time()

    print("cwd: %s" % (os.getcwd()))
    sys.stdout.flush()

    #    pipes = startfunnel(os.path.join(os.getcwd(), "tmp/"), name)

    print("Reading Data")
    # from numpy.random import randn
    #  m=1000
    #  n=100
    #  A=randn(m,n)
    #  x_true=(randn(n)/n)*float64(randn(n)<0.8)
    #  b=A.dot(x_true)+0.5*randn(m)

    df = pd.read_csv("./open_data/simple.txt", sep=" ", header=None)
    print(df.shape)
    X = np.array(df.iloc[:, :df.shape[1] - 1], dtype='float32', order='C')
    y = np.array(df.iloc[:, df.shape[1] - 1], dtype='float32', order='C')

    if choosealphalambda == 1 or choosealphalambda == 3:
        alphas = [1E-1, 0.3, 0.5, 1.0]
    else:
        alphas = None
    if choosealphalambda == 2 or choosealphalambda == 3:
        lambdas = [2, 1E-2, 1E-3, 1E-5]
    else:
        lambdas = None

    t1 = time.time()
    rmse_train, rmse_test = run_glm(X,
                                    y,
                                    nGPUs=nGPUs,
                                    nlambda=nLambdas,
                                    nfolds=nFolds,
                                    nalpha=nAlphas,
                                    validFraction=validFraction,
                                    verbose=0,
                                    name=name,
                                    alphas=alphas,
                                    lambdas=lambdas,
                                    tolerance=0.3)

    # check rmse
    print(rmse_train[0, 0])
    print(rmse_train[0, 1])
    print(rmse_train[0, 2])
    print(rmse_test[0, 2])
    sys.stdout.flush()

    if validFraction == 0.0:
        if nLambdas > 50:
            if nFolds == 1:
                assert rmse_train[0, 0] < 0.04
                assert rmse_train[0, 1] < 0.04
                assert rmse_train[0, 2] < 0.04
                assert rmse_test[0, 2] < 0.04

                assert rmse_train[-1, 0] < 0.05
                assert rmse_train[-1, 1] < 0.05
                assert rmse_train[-1, 2] < 0.05
                assert rmse_test[-1, 2] < 0.05
            else:
                assert rmse_train[0, 0] < 0.37
                assert rmse_train[0, 1] < 0.22
                assert rmse_train[0, 2] < 0.4
                assert rmse_test[0, 2] < 0.4

                assert rmse_train[-1, 0] < 0.37
                assert rmse_train[-1, 1] < 0.77
                assert rmse_train[-1, 2] < 0.4
                assert rmse_test[-1, 2] < 0.4
        else:
            if nFolds == 1:
                assert rmse_train[0, 0] < 0.11
                assert rmse_train[0, 1] < 0.12
                assert rmse_train[0, 2] < 0.1
                assert rmse_test[0, 2] < 0.1

                assert rmse_train[-1, 0] < 0.11
                assert rmse_train[-1, 1] < 0.12
                assert rmse_train[-1, 2] < 0.1
                assert rmse_test[-1, 2] < 0.1
            else:
                assert rmse_train[0, 0] < 0.37
                assert rmse_train[0, 1] < 0.22
                assert rmse_train[0, 2] < 0.4
                assert rmse_test[0, 2] < 0.4

                assert rmse_train[-1, 0] < 0.37
                assert rmse_train[-1, 1] < 0.24
                assert rmse_train[-1, 2] < 0.4
                assert rmse_test[-1, 2] < 0.4
    else:
        if nLambdas > 50:
            if nFolds == 1:
                assert rmse_train[0, 0] < 0.4
                assert rmse_train[0, 1] < 0.4
                assert rmse_train[0, 2] < 0.51
                assert rmse_test[0, 2] < 0.51

                assert rmse_train[-1, 0] < 0.51
                assert rmse_train[-1, 1] < 0.51
                assert rmse_train[-1, 2] < 0.51
                assert rmse_test[-1, 2] < 0.51
            else:
                assert rmse_train[0, 0] < 0.51
                assert rmse_train[0, 1] < 0.51
                assert rmse_train[0, 2] < 2
                assert rmse_test[0, 2] < 2

                assert rmse_train[-1, 0] < 0.54
                assert rmse_train[-1, 1] < 0.54
                assert rmse_train[-1, 2] < 2.2
                assert rmse_test[-1, 2] < 2.2
        else:
            if nFolds == 1:
                assert rmse_train[0, 0] < 0.4
                assert rmse_train[0, 1] < 0.4
                assert rmse_train[0, 2] < 2
                assert rmse_test[0, 2] < 2

                assert rmse_train[-1, 0] < 0.51
                assert rmse_train[-1, 1] < 0.51
                assert rmse_train[-1, 2] < 2
                assert rmse_test[-1, 2] < 2
            else:
                assert rmse_train[0, 0] < 0.45
                assert rmse_train[0, 1] < 0.3
                assert rmse_train[0, 2] < 2
                assert rmse_test[0, 2] < 2

                assert rmse_train[-1, 0] < 0.45
                assert rmse_train[-1, 1] < 0.3
                assert rmse_train[-1, 2] < 2
                assert rmse_test[-1, 2] < 2

    print('/n Total execution time:%d' % (time.time() - t1))

    print("TEST PASSED")
    sys.stdout.flush()

    print("Time taken: {}".format(time.time() - t))
    #    endfunnel(pipes)
    print("DONE.")
    sys.stdout.flush()
Beispiel #10
0
def fun(nGPUs=1, nFolds=1, nLambdas=100, nAlphas=8, validFraction=0.2):
    name = str(sys._getframe().f_code.co_name)
    t = time.time()

    print("cwd: %s" % (os.getcwd()))
    sys.stdout.flush()

    name = sys._getframe(1).f_code.co_name
    #    pipes = startfunnel(os.path.join(os.getcwd(), "tmp/"), name)

    print("Reading Data")
    # from numpy.random import randn
    #  m=1000
    #  n=100
    #  A=randn(m,n)
    #  x_true=(randn(n)/n)*float64(randn(n)<0.8)
    #  b=A.dot(x_true)+0.5*randn(m)

    # Rscript ipums.R  runs glmnet on ipums
    #
    df = feather.read_dataframe("./data/ipums.feather")
    print(df.shape)
    X = np.array(df.iloc[:, :df.shape[1] - 1], dtype='float32', order='C')
    y = np.array(df.iloc[:, df.shape[1] - 1], dtype='float32', order='C')

    t1 = time.time()
    rmse_train, rmse_test = run_glm(X,
                                    y,
                                    nGPUs=nGPUs,
                                    nlambda=nLambdas,
                                    nfolds=nFolds,
                                    nalpha=nAlphas,
                                    validFraction=validFraction,
                                    verbose=0,
                                    name=name)

    # check rmse
    print(rmse_train[0, 0])
    print(rmse_train[0, 1])
    print(rmse_train[0, 2])
    print(rmse_test[0, 2])
    sys.stdout.flush()

    if validFraction == 0.0:
        assert rmse_train[0, 0] < 34000
        assert rmse_train[0, 1] < 34000
        assert rmse_train[0, 2] < 34000
        assert rmse_test[0, 2] < 34000
    else:
        if nLambdas > 20:
            assert rmse_train[0, 0] < 30000
            assert rmse_train[0, 1] < 30000
            assert rmse_train[0, 2] < 30000
            assert rmse_test[0, 2] < 30000
        else:
            assert rmse_train[0, 0] < 34000
            assert rmse_train[0, 1] < 34000
            assert rmse_train[0, 2] < 34000
            assert rmse_test[0, 2] < 37000

    print('/n Total execution time:%d' % (time.time() - t1))

    print("TEST PASSED")
    sys.stdout.flush()

    print("Time taken: {}".format(time.time() - t))
    #    endfunnel(pipes)
    print("DONE.")
    sys.stdout.flush()
Beispiel #11
0
def fun(nGPUs=1, nFolds=1, nLambdas=100, nAlphas=8, validFraction=0.2):
    name = str(sys._getframe().f_code.co_name)
    name = sys._getframe(1).f_code.co_name
    t = time.time()

    print("cwd: %s" % (os.getcwd()))
    sys.stdout.flush()


    print("Reading Data")
    # from numpy.random import randn
    #  m=1000
    #  n=100
    #  A=randn(m,n)
    #  x_true=(randn(n)/n)*float64(randn(n)<0.8)
    #  b=A.dot(x_true)+0.5*randn(m)

    # Rscript ipums.R  runs glmnet on ipums
    #
    df = pd.read_csv("./data/ipums_1k.csv")
    print(df.shape)
    X = np.array(df.iloc[:, :df.shape[1] - 1], dtype='float32', order='C')
    y = np.array(df.iloc[:, df.shape[1] - 1], dtype='float32', order='C')
    #X = df.iloc[:, :df.shape[1] - 1]
    #y = df.iloc[:, df.shape[1] - 1]

    t1 = time.time()
    # by default, tol=1E-2 for h2o4gpu and don't try to be strictly as accurate as h2o-3, so use tolernace that represents how well we expect to do with default tol for glm algo.
    rmse_train, rmse_test = run_glm(X, y, nGPUs=nGPUs, nlambda=nLambdas, nfolds=nFolds, nalpha=nAlphas,
                                        validFraction=validFraction, verbose=0, name=name, tolerance = 0.34)

    # check rmse
    print(rmse_train[0, 0])
    print(rmse_train[0, 1])
    print(rmse_train[0, 2])
    print(rmse_test[0, 2])
    sys.stdout.flush()

    if validFraction==0.0:
        assert rmse_train[0, 0] < 54000
        assert rmse_train[0, 1] < 54000
        assert rmse_train[0, 2] < 54000
        assert rmse_test[0, 2] < 54000
    else:
        if nLambdas>20:
            assert rmse_train[0, 0] < 50000
            assert rmse_train[0, 1] < 50000
            assert rmse_train[0, 2] < 50000
            assert rmse_test[0, 2] < 50000
        else:
            assert rmse_train[0, 0] < 59000
            assert rmse_train[0, 1] < 59000
            assert rmse_train[0, 2] < 59000
            assert rmse_test[0, 2] < 59000

    print('/n Total execution time:%d' % (time.time() - t1))

    print("TEST PASSED")
    sys.stdout.flush()

    print("Time taken: {}".format(time.time() - t))
    #    endfunnel(pipes)
    print("DONE.")
    sys.stdout.flush()
Beispiel #12
0
def func(nGPUs=1, nFolds=1, nLambdas=100, nAlphas=8, validFraction=0.2, verbose=0,family="elasticnet", print_all_errors=False, tolerance=.001):
    name = str(sys._getframe().f_code.co_name)
    name = str(sys._getframe(1).f_code.co_name)
    t = time.time()

    print("cwd: %s" % (os.getcwd()))
    sys.stdout.flush()

    print("Reading Data")
    df = pd.read_csv("./open_data/creditcard.csv")
    print(df.shape)
    X = np.array(df.iloc[:, :df.shape[1] - 1], dtype='float32', order='C')
    y = np.array(df.iloc[:, df.shape[1] - 1], dtype='float32', order='C')

    t1 = time.time()

    logloss_train, logloss_test = run_glm(X, y, nGPUs=nGPUs, nlambda=nLambdas, nfolds=nFolds, nalpha=nAlphas,
                validFraction=validFraction, verbose=verbose,family=family,print_all_errors=print_all_errors,tolerance=tolerance, name=name)


    # check logloss
    print(logloss_train[0, 0])
    print(logloss_train[0, 1])
    print(logloss_train[0, 2])
    print(logloss_test[0, 2])
    sys.stdout.flush()

    #Train only
    if validFraction==0.0 and nFolds == 0:
        assert logloss_train[0, 0] < .47
        assert logloss_train[1,0] < .47
        assert logloss_train[2,0] < .47
        assert logloss_test[0, 0] < .47
        assert logloss_test[1, 0] < .47
        assert logloss_test[2, 0] < .47

    #Train + nfolds
    if validFraction==0.0 and nFolds > 0:
        assert logloss_train[0, 0] < .48
        assert logloss_train[0, 1] < .44
        assert logloss_train[1, 0] < .48
        assert logloss_train[1, 1] < .48
        assert logloss_train[2, 0] < .48
        assert logloss_train[2, 1] < .44
        assert logloss_test[0, 0] < .48
        assert logloss_test[0, 1] < .44
        assert logloss_test[1, 0] < .48
        assert logloss_test[1, 1] < .48
        assert logloss_test[2, 0] < .48
        assert logloss_test[2, 1] < .44

    #Train + validation
    if validFraction > 0.0 and nFolds == 0:
        assert logloss_train[0, 0] < .48
        assert logloss_train[0, 2] < .44
        assert logloss_train[1, 0] < .48
        assert logloss_train[1, 2] < .44
        assert logloss_train[2, 0] < .48
        assert logloss_train[2, 2] < .44
        assert logloss_test[0, 0] < .48
        assert logloss_test[0, 2] < .44
        assert logloss_test[1, 0] < .48
        assert logloss_test[1, 2] < .44
        assert logloss_test[2, 0] < .48
        assert logloss_test[2, 2] < .44

    #Train + validation + nfolds
    if validFraction > 0.0 and nFolds > 0:
        assert logloss_train[0, 0] < .48
        assert logloss_train[0, 1] < .48
        assert logloss_train[0, 2] < .44
        assert logloss_train[1, 0] < .48
        assert logloss_train[1, 1] < .48
        assert logloss_train[1, 2] < .44
        assert logloss_train[2, 0] < .48
        assert logloss_train[2, 1] < .48
        assert logloss_train[2, 2] < .44
        assert logloss_test[0, 0] < .48
        assert logloss_test[0, 1] < .48
        assert logloss_test[0, 2] < .44
        assert logloss_test[1, 0] < .48
        assert logloss_test[1, 1] < .48
        assert logloss_test[1, 2] < .44
        assert logloss_test[2, 0] < .48
        assert logloss_test[2, 1] < .48
        assert logloss_test[2, 2] < .44
    

    sys.stdout.flush()

    print('/n Total execution time:%d' % (time.time() - t1))

    print("TEST PASSED")
    sys.stdout.flush()

    print("Time taken: {}".format(time.time() - t))

    print("DONE.")
    sys.stdout.flush()
Beispiel #13
0
    def fun(nGPUs=1, nFolds=1, nLambdas=100, nAlphas=8, validFraction=0.2, whichdata=0, double_precision=False):
        name = str(sys._getframe().f_code.co_name)
        t = time.time()
    
        print("cwd: %s" % (os.getcwd()))
        sys.stdout.flush()
    
        name = sys._getframe(1).f_code.co_name
        #    pipes = startfunnel(os.path.join(os.getcwd(), "tmp/"), name)
    
        print("Getting Data")
        from h2o4gpu.datasets import fetch_20newsgroups, fetch_20newsgroups_vectorized, fetch_california_housing, \
            fetch_covtype, fetch_kddcup99, fetch_lfw_pairs, fetch_lfw_people, fetch_mldata, fetch_olivetti_faces, \
            fetch_rcv1, fetch_species_distributions
        from h2o4gpu.model_selection import train_test_split
    
        # Fetch dataset
        if whichdata == 0:
            data = fetch_20newsgroups() # runs
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 1:
            data = fetch_20newsgroups_vectorized() # sparse
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 2:
            data = fetch_california_housing() # runs
            sizetokeep = 1000
        elif whichdata == 3:
            data = fetch_covtype()
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 4:
            data = fetch_kddcup99() # strings -> numeric
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 5:
            data = fetch_lfw_pairs()
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 6:
            data = fetch_lfw_people()
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 7:
            data = fetch_mldata('iris')
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 8:
            data = fetch_mldata('leukemia') # runs
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 9:
            data = fetch_mldata('Whistler Daily Snowfall')
            sizetokeep = 1000  # 1k rows for now
        elif whichdata == 10:
            data = fetch_olivetti_faces() # runs
            sizetokeep = 100
        elif whichdata == 11:
            data = fetch_rcv1()
            sizetokeep = 1000  # 1k rows for now
            #data = data.todense() # FIXME: glm and kmeans h2o4gpu currently only supports dense matrices
        elif whichdata == 12:
            data = fetch_species_distributions()
            sizetokeep = 1000  # 1k rows for now
        else:
            ValueError("No such whichdata")
    
        try:
            sizetokeep = min(sizetokeep,len(data.data[:,0]))
            X = data.data[0:sizetokeep, :]
        except:
            sizetokeep = min(sizetokeep, len(data.data[:]))
            X = data.data[0:sizetokeep]
        y = data.target[0:sizetokeep]
        print("Got Data")

        import numpy as np

        # Create 0.8/0.2 train/test split
        print("Split Data")
        X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, train_size=0.8,
                                                            random_state=42)
    
        print("Encode Data")
        # from h2o4gpu.preprocessing import Imputer
        # imp = Imputer(missing_values='NaN', strategy='mean', axis=0)
        # imp.fit(X, y)
        # Xencoded = imp.transform(X)
        # yencoded = imp.transform(y)
    
        import pandas as pd
        X_test_pd = pd.DataFrame(X_test)
        X_train_pd = pd.DataFrame(X_train)
    
        # Importing LabelEncoder and initializing it
        from h2o4gpu.preprocessing import LabelEncoder
        le = LabelEncoder()
        # Iterating over all the common columns in train and test
        for col in X_test_pd.columns.values:
            # Encoding only categorical variables
            if X_test_pd[col].dtypes == 'object' or X_test_pd[col].dtypes == 'bool':
                # Using whole data to form an exhaustive list of levels
                data = X_train_pd[col].append(X_test_pd[col])
                le.fit(data.values)
                X_train_pd[col] = le.transform(X_train_pd[col])
                X_test_pd[col] = le.transform(X_test_pd[col])
    
        X_train_pd = pd.get_dummies(X_train_pd).fillna(0.0)
        X_test_pd = pd.get_dummies(X_test_pd).fillna(0.0)
        y_train_pd = pd.Series(y_train).fillna(0.0)
        y_test_pd = pd.Series(y_test).fillna(0.0)
    
        # get back numpy
        X_test = X_test_pd.values
        X_train = X_train_pd.values
        y_test = y_test_pd.values
        y_train = y_train_pd.values
    
        if double_precision:
            mynptype = np.float64
        else:
            mynptype = np.float32
        X_test = X_test.astype(mynptype)
        X_train = X_train.astype(np.float64)
        y_test = y_test.astype(np.float64)
        y_train = y_train.astype(np.float64)

        # TODO: Should write this to file and avoid doing encoding if already exists
    
        t1 = time.time()
        print("Start ElasticNetH2O")
        rmse_train, rmse_test = run_glm(X_train, y_train, X_test, y_test, nGPUs=nGPUs, nlambda=nLambdas, nfolds=nFolds,
                                        nalpha=nAlphas,
                                        validFraction=validFraction, verbose=10, name=name, tolerance=0.2, tol=1E-2, tol_seek_factor=1.0)
        print("End ElasticNetH2O")
    
        # check rmse
        print(rmse_train[0, 0])
        print(rmse_train[0, 1])
        print(rmse_train[0, 2])
        print(rmse_test[0, 2])
        sys.stdout.flush()
    
        print('/n Total execution time:%d' % (time.time() - t1))
    
        print("TEST PASSED")
        sys.stdout.flush()
    
        print("Time taken: {}".format(time.time() - t))
        #    endfunnel(pipes)
        print("DONE.")
        sys.stdout.flush()
Beispiel #14
0
def fun(nGPUs=1, nFolds=1, nLambdas=100, nAlphas=8, validFraction=0.2):
    name = str(sys._getframe().f_code.co_name)
    t = time.time()

    print("cwd: %s" % (os.getcwd()))
    sys.stdout.flush()

    name = sys._getframe(1).f_code.co_name
    #    pipes = startfunnel(os.path.join(os.getcwd(), "tmp/"), name)

    print("Reading Data")
    # from numpy.random import randn
    #  m=1000
    #  n=100
    #  A=randn(m,n)
    #  x_true=(randn(n)/n)*float64(randn(n)<0.8)
    #  b=A.dot(x_true)+0.5*randn(m)

    # Rscript ipums.R  runs glmnet on ipums
    #
    df = feather.read_dataframe("./data/ipums.feather")
    print(df.shape)
    X = np.array(df.iloc[:, :df.shape[1] - 1], dtype='float32', order='C')
    y = np.array(df.iloc[:, df.shape[1] - 1], dtype='float32', order='C')

    t1 = time.time()
    rmse_train, rmse_test = run_glm(X, y, nGPUs=nGPUs, nlambda=nLambdas, nfolds=nFolds, nalpha=nAlphas,
                                        validFraction=validFraction, verbose=0, name=name)

    # check rmse
    print(rmse_train[0, 0])
    print(rmse_train[0, 1])
    print(rmse_train[0, 2])
    print(rmse_test[0, 2])
    sys.stdout.flush()

    if validFraction==0.0:
        assert rmse_train[0, 0] < 34000
        assert rmse_train[0, 1] < 34000
        assert rmse_train[0, 2] < 34000
        assert rmse_test[0, 2] < 34000
    else:
        if nLambdas>20:
            assert rmse_train[0, 0] < 30000
            assert rmse_train[0, 1] < 30000
            assert rmse_train[0, 2] < 30000
            assert rmse_test[0, 2] < 30000
        else:
            assert rmse_train[0, 0] < 34000
            assert rmse_train[0, 1] < 34000
            assert rmse_train[0, 2] < 34000
            assert rmse_test[0, 2] < 37000

    print('/n Total execution time:%d' % (time.time() - t1))

    print("TEST PASSED")
    sys.stdout.flush()

    print("Time taken: {}".format(time.time() - t))
    #    endfunnel(pipes)
    print("DONE.")
    sys.stdout.flush()