Skip to content

Instantly share code, notes, and snippets.

@Niranjankumar-c
Last active March 31, 2019 03:24
Show Gist options
  • Save Niranjankumar-c/fabada6fd7456341e97d351f26b364fa to your computer and use it in GitHub Desktop.
Save Niranjankumar-c/fabada6fd7456341e97d351f26b364fa to your computer and use it in GitHub Desktop.
Generate some dummy data for feed forward neural network
#creating my own color map for better visualization
my_cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", ["red","yellow","green"])
#Generating 1000 observations with 4 labels - multi class
data, labels = make_blobs(n_samples=1000, centers=4, n_features=2, random_state=0)
print(data.shape, labels.shape)
#visualize the data
plt.scatter(data[:,0], data[:,1], c=labels, cmap=my_cmap)
plt.show()
#converting the multi-class to binary
labels_orig = labels
labels = np.mod(labels_orig, 2)
plt.scatter(data[:,0], data[:,1], c=labels, cmap=my_cmap)
plt.show()
#split the binary data
X_train, X_val, Y_train, Y_val = train_test_split(data, labels, stratify=labels, random_state=0)
print(X_train.shape, X_val.shape)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment