Skip to content

Instantly share code, notes, and snippets.

@zafarali
Last active December 2, 2015 04:20
Show Gist options
  • Select an option

  • Save zafarali/e474b330cdb4057ac8c3 to your computer and use it in GitHub Desktop.

Select an option

Save zafarali/e474b330cdb4057ac8c3 to your computer and use it in GitHub Desktop.
# Load the data streamer:
ds = IOutils.data_streamer(num_sets='all')
# obtains the unique rows in a dataset
def unique_rows(data):
uniq = np.unique(data.view(data.dtype.descr * data.shape[1]))
return uniq.view(data.dtype).reshape(-1, data.shape[1])
X, Y = ds.next()
Y = np.array(Y)
urows = list(unique_rows(Y))
def transform_vector(y):
for i, u in enumerate(urows):
if all(y == u):
return i
# now use as follows:
for X,Y in ds:
Y = np.array(Y)
Y_transformed = np.apply_along_axis(transform_vector, axis=1, arr=Y).astype(np.int32)
# you might need to do some reshaping here.
MyClassifier.fit(X,Y_transformed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment