text stringlengths 1 93.6k |
|---|
# dense buckets
|
fj_d = np.load(filename_j_d, mmap_mode='r+')
|
# print("start=" + str(start) + " end=" + str(end)
|
# + " end - start=" + str(end - start) + " "
|
# + str(fj_d[start:end, :].shape) + " "
|
# + str(len(buckets[j])))
|
fj_d[start:end, :] = X_int[buckets[j], :]
|
del fj_d
|
# sparse buckets
|
fj_s = np.load(filename_j_s, mmap_mode='r+')
|
# print("start=" + str(start) + " end=" + str(end)
|
# + " end - start=" + str(end - start) + " "
|
# + str(fj_s[start:end, :].shape) + " "
|
# + str(len(buckets[j])))
|
fj_s[start:end, :] = X_cat[buckets[j], :]
|
del fj_s
|
# update counters for next step
|
total_counter[j] += counter[j]
|
# 2nd pass of FYR shuffle
|
# check if data already exists
|
for j in range(days):
|
filename_j = npzfile + "_{0}_reordered.npz".format(j)
|
if path.exists(filename_j):
|
print("Using existing " + filename_j)
|
else:
|
recreate_flag = True
|
# reorder within buckets
|
if recreate_flag:
|
for j in range(days):
|
filename_j_y = npzfile + "_{0}_intermediate_y.npy".format(j)
|
filename_j_d = npzfile + "_{0}_intermediate_d.npy".format(j)
|
filename_j_s = npzfile + "_{0}_intermediate_s.npy".format(j)
|
fj_y = np.load(filename_j_y)
|
fj_d = np.load(filename_j_d)
|
fj_s = np.load(filename_j_s)
|
indices = range(total_per_file[j])
|
if randomize == "day" or randomize == "total":
|
if data_split == "none" or j < days - 1:
|
indices = np.random.permutation(range(total_per_file[j]))
|
filename_r = npzfile + "_{0}_reordered.npz".format(j)
|
print("Reordering (2nd pass) " + filename_r)
|
np.savez_compressed(
|
filename_r,
|
X_cat=fj_s[indices, :],
|
X_int=fj_d[indices, :],
|
y=fj_y[indices],
|
)
|
'''
|
# sanity check (under no reordering norms should be zero)
|
for i in range(days):
|
filename_i_o = npzfile + "_{0}_processed.npz".format(i)
|
print(filename_i_o)
|
with np.load(filename_i_o) as data_original:
|
X_cat_o = data_original["X_cat"]
|
X_int_o = data_original["X_int"]
|
y_o = data_original["y"]
|
filename_i_r = npzfile + "_{0}_reordered.npz".format(i)
|
print(filename_i_r)
|
with np.load(filename_i_r) as data_reordered:
|
X_cat_r = data_reordered["X_cat"]
|
X_int_r = data_reordered["X_int"]
|
y_r = data_reordered["y"]
|
print(np.linalg.norm(y_o - y_r))
|
print(np.linalg.norm(X_int_o - X_int_r))
|
print(np.linalg.norm(X_cat_o - X_cat_r))
|
'''
|
else:
|
print("Concatenating multiple days into %s.npz file" % str(d_path + o_filename))
|
# load and concatenate data
|
for i in range(days):
|
filename_i = npzfile + "_{0}_processed.npz".format(i)
|
with np.load(filename_i) as data:
|
if i == 0:
|
X_cat = data["X_cat"]
|
X_int = data["X_int"]
|
y = data["y"]
|
else:
|
X_cat = np.concatenate((X_cat, data["X_cat"]))
|
X_int = np.concatenate((X_int, data["X_int"]))
|
y = np.concatenate((y, data["y"]))
|
print("Loaded day:", i, "y = 1:", len(y[y == 1]), "y = 0:", len(y[y == 0]))
|
with np.load(d_path + d_file + "_fea_count.npz") as data:
|
counts = data["counts"]
|
print("Loaded counts!")
|
np.savez_compressed(
|
d_path + o_filename + ".npz",
|
X_cat=X_cat,
|
X_int=X_int,
|
y=y,
|
counts=counts,
|
)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.