support/parse_data.py
def quantum():
    '''
    Data preparation function, specific to the "quantum physics" dataset.
    URL: http://osmot.cs.cornell.edu/kddcup/datasets.html
    '''
    dataset = "quantum"
    dinfo = classes.DataInfo()
    dinfo.mname = "LgstReg" # hard-coded model name.
    

    print("Preparation (", dataset, ")...")
    toread = os.path.join(DATA_PATH,
                          dataset,
                          "phy_train.dat")
    # NOTE: only "train" has labels, so we split this dataset into
    # train/test subsets for a supervised learning routine.

    n = 50000
    d = 78
    X_tr = np.zeros( (n//2,d), dtype=np.float64 )
    y_tr = np.zeros( (n//2,1), dtype=np.uint8 )
    X_te = np.zeros( (n//2,d), dtype=np.float64 )
    y_te = np.zeros( (n//2,1), dtype=np.uint8 )
    
    with open(toread, newline="") as f_table:
        f_reader = csv.reader(f_table, delimiter="\t")
        idx = 0
        switcher = True
        for line in f_reader:

            # Arbitrarily let first half be training, second half testing.
            if switcher:
                y_tr[idx,0] = np.uint8(line[1])
                X_tr[idx,:] = np.array(line[2:-1], dtype=np.float64)
                idx += 1
            else:
                y_te[idx,0] = np.uint8(line[1])
                X_te[idx,:] = np.array(line[2:-1], dtype=np.float64)
                idx += 1

            # Once we've covered half the data, start on test data.
            if idx == n//2:
                switcher = False
                idx = 0

    print("Writing inputs...")
    towrite = os.path.join("data", dataset, ("X_tr" + ".dat"))
    with open(towrite, mode="bw") as g_bin:
        X_tr.tofile(g_bin)
    dinfo.X_tr["shape"] = (n//2,d)
    dinfo.X_tr["path"] = towrite
    dinfo.X_tr["dtype"] = np.float64
    towrite = os.path.join("data", dataset, ("X_te" + ".dat"))
    with open(towrite, mode="bw") as g_bin:
        X_te.tofile(g_bin)
    dinfo.X_te["shape"] = (n//2,d)
    dinfo.X_te["path"] = towrite
    dinfo.X_te["dtype"] = np.float64

    print("Writing outputs...")
    towrite = os.path.join("data", dataset, ("y_tr" + ".dat"))
    with open(towrite, mode="bw") as g_bin:
        y_tr.tofile(g_bin)
    dinfo.y_tr["shape"] = (n//2,1)
    dinfo.y_tr["path"] = towrite
    dinfo.y_tr["dtype"] = np.uint8
    towrite = os.path.join("data", dataset, ("y_te" + ".dat"))
    with open(towrite, mode="bw") as g_bin:
        y_te.tofile(g_bin)
    dinfo.y_te["shape"] = (n//2,1)
    dinfo.y_te["path"] = towrite
    dinfo.y_te["dtype"] = np.uint8

    # Save the dinfo dictionary for future use (so we don't have to read
    # the original data every time).
    towrite = os.path.join("data", dataset, "info.dat")
    with open(towrite, mode="wb") as f:
        pickle.dump(dinfo, f)

    # Finally, return the dinfo dict.
    return dinfo

    Data preparation function, specific to the "quantum physics" dataset.
    URL: http://osmot.cs.cornell.edu/kddcup/datasets.html
    
Data preparation function, specific to the "quantum physics" dataset.
Data preparation function specific to the " quantum physics " dataset .
def quantum():
    dataset = "quantum"
    dinfo = classes.DataInfo()
    dinfo.mname = "LgstReg" 
    print("Preparation (", dataset, ")...")
    toread = os.path.join(DATA_PATH,
                          dataset,
                          "phy_train.dat")
    n = 50000
    d = 78
    X_tr = np.zeros( (n//2,d), dtype=np.float64 )
    y_tr = np.zeros( (n//2,1), dtype=np.uint8 )
    X_te = np.zeros( (n//2,d), dtype=np.float64 )
    y_te = np.zeros( (n//2,1), dtype=np.uint8 )
    with open(toread, newline="") as f_table:
        f_reader = csv.reader(f_table, delimiter="\t")
        idx = 0
        switcher = True
        for line in f_reader:
            if switcher:
                y_tr[idx,0] = np.uint8(line[1])
                X_tr[idx,:] = np.array(line[2:-1], dtype=np.float64)
                idx += 1
            else:
                y_te[idx,0] = np.uint8(line[1])
                X_te[idx,:] = np.array(line[2:-1], dtype=np.float64)
                idx += 1
            if idx == n//2:
                switcher = False
                idx = 0
    print("Writing inputs...")
    towrite = os.path.join("data", dataset, ("X_tr" + ".dat"))
    with open(towrite, mode="bw") as g_bin:
        X_tr.tofile(g_bin)
    dinfo.X_tr["shape"] = (n//2,d)
    dinfo.X_tr["path"] = towrite
    dinfo.X_tr["dtype"] = np.float64
    towrite = os.path.join("data", dataset, ("X_te" + ".dat"))
    with open(towrite, mode="bw") as g_bin:
        X_te.tofile(g_bin)
    dinfo.X_te["shape"] = (n//2,d)
    dinfo.X_te["path"] = towrite
    dinfo.X_te["dtype"] = np.float64
    print("Writing outputs...")
    towrite = os.path.join("data", dataset, ("y_tr" + ".dat"))
    with open(towrite, mode="bw") as g_bin:
        y_tr.tofile(g_bin)
    dinfo.y_tr["shape"] = (n//2,1)
    dinfo.y_tr["path"] = towrite
    dinfo.y_tr["dtype"] = np.uint8
    towrite = os.path.join("data", dataset, ("y_te" + ".dat"))
    with open(towrite, mode="bw") as g_bin:
        y_te.tofile(g_bin)
    dinfo.y_te["shape"] = (n//2,1)
    dinfo.y_te["path"] = towrite
    dinfo.y_te["dtype"] = np.uint8
    towrite = os.path.join("data", dataset, "info.dat")
    with open(towrite, mode="wb") as f:
        pickle.dump(dinfo, f)
    return dinfo
def quantum ( ) : dataset = "quantum" dinfo = classes . DataInfo ( ) dinfo . mname = "LgstReg" print ( "Preparation (" , dataset , ")..." ) toread = os . path . join ( DATA_PATH , dataset , "phy_train.dat" ) n = 50000 d = 78 X_tr = np . zeros ( ( n // 2 , d ) , dtype = np . float64 ) y_tr = np . zeros ( ( n // 2 , 1 ) , dtype = np . uint8 ) X_te = np . zeros ( ( n // 2 , d ) , dtype = np . float64 ) y_te = np . zeros ( ( n // 2 , 1 ) , dtype = np . uint8 ) with open ( toread , newline = "" ) as f_table : f_reader = csv . reader ( f_table , delimiter = "\t" ) idx = 0 switcher = True for line in f_reader : if switcher : y_tr [ idx , 0 ] = np . uint8 ( line [ 1 ] ) X_tr [ idx , : ] = np . array ( line [ 2 : - 1 ] , dtype = np . float64 ) idx += 1 else : y_te [ idx , 0 ] = np . uint8 ( line [ 1 ] ) X_te [ idx , : ] = np . array ( line [ 2 : - 1 ] , dtype = np . float64 ) idx += 1 if idx == n // 2 : switcher = False idx = 0 print ( "Writing inputs..." ) towrite = os . path . join ( "data" , dataset , ( "X_tr" + ".dat" ) ) with open ( towrite , mode = "bw" ) as g_bin : X_tr . tofile ( g_bin ) dinfo . X_tr [ "shape" ] = ( n // 2 , d ) dinfo . X_tr [ "path" ] = towrite dinfo . X_tr [ "dtype" ] = np . float64 towrite = os . path . join ( "data" , dataset , ( "X_te" + ".dat" ) ) with open ( towrite , mode = "bw" ) as g_bin : X_te . tofile ( g_bin ) dinfo . X_te [ "shape" ] = ( n // 2 , d ) dinfo . X_te [ "path" ] = towrite dinfo . X_te [ "dtype" ] = np . float64 print ( "Writing outputs..." ) towrite = os . path . join ( "data" , dataset , ( "y_tr" + ".dat" ) ) with open ( towrite , mode = "bw" ) as g_bin : y_tr . tofile ( g_bin ) dinfo . y_tr [ "shape" ] = ( n // 2 , 1 ) dinfo . y_tr [ "path" ] = towrite dinfo . y_tr [ "dtype" ] = np . uint8 towrite = os . path . join ( "data" , dataset , ( "y_te" + ".dat" ) ) with open ( towrite , mode = "bw" ) as g_bin : y_te . tofile ( g_bin ) dinfo . y_te [ "shape" ] = ( n // 2 , 1 ) dinfo . y_te [ "path" ] = towrite dinfo . y_te [ "dtype" ] = np . uint8 towrite = os . path . join ( "data" , dataset , "info.dat" ) with open ( towrite , mode = "wb" ) as f : pickle . dump ( dinfo , f ) return dinfo
Data preparation function, specific to the "quantum physics" dataset.
Data preparation function specific to the " quantum physics " dataset .
'''
    Data preparation function, specific to the "quantum physics" dataset.
    URL: http://osmot.cs.cornell.edu/kddcup/datasets.html
    ''' # hard-coded model name. # NOTE: only "train" has labels, so we split this dataset into # train/test subsets for a supervised learning routine. # Arbitrarily let first half be training, second half testing. # Once we've covered half the data, start on test data. # Save the dinfo dictionary for future use (so we don't have to read # the original data every time). # Finally, return the dinfo dict.