def subsample_X(X, labels, num_samples=<NUM_LIT:1000>):
if X.shape[<NUM_LIT:0>] > num_samples:<EOL><INDENT>print("<STR_LIT>".format(int(num_samples), X.shape))<EOL>if labels is not None:<EOL><INDENT>subsample = []<EOL>for _, _, _, _, index, _ in scatter_label_generator(labels, X, (<NUM_LIT:0>, None, None)):<EOL><INDENT>subsample.append(np.random.choice(index, size=max(<NUM_LIT:2>, int(index.size*(float(num_samples)/X.shape[<NUM_LIT:0>]))), replace=False))<EOL><DEDENT>subsample = np.hstack(subsample)<EOL><DEDENT>else:<EOL><INDENT>subsample = np.random.choice(X.shape[<NUM_LIT:0>], size=<NUM_LIT:1000>, replace=False)<EOL><DEDENT>X = X[subsample]<EOL>labels = labels[subsample]<EOL><DEDENT>return X, labels<EOL>
Stratified subsampling if labels are given.
This means due to rounding errors you might get a little differences between the
num_samples and the returned subsampled X.