Skip to content

Instantly share code, notes, and snippets.

@BenjaminFraser
Last active June 29, 2018 18:45
Show Gist options
  • Save BenjaminFraser/e7443ce01a98417388fc83e3483732ab to your computer and use it in GitHub Desktop.
Save BenjaminFraser/e7443ce01a98417388fc83e3483732ab to your computer and use it in GitHub Desktop.
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# make up random data for bird wingspans and weights for golden eagles and horned owls
bird_wingspans = np.concatenate([np.random.randint(170, 230, size = 50)/100.0,
np.random.randint(60, 100, size = 50)/100.0])
bird_weights = np.concatenate([(11 - 10)*np.random.randn(50)+10, np.abs(np.random.randn(50))+1])
# combine X vectors into a 2-dimensional array with 100 rows and 2 columns
X = np.vstack((bird_wingspans, bird_weights)).T
# create labels for our input data - first 50 are Golden Eagles (binary 0), last 50 are Horned Owls (binary 1)
y = np.concatenate([np.zeros(50), np.ones(50)])
# confirm shapes of generated data
print("The shape of our input matrix, X, is: {0}.".format(X.shape))
print("The shape of our output vector, y, is: {0}.".format(y.shape))
# plot our data on a scatter graph using matplotlib
# first 50 samples = Golden Eagle - plot both input features (columns 0 and 1 of X)
plt.scatter(X[:50, 0], X[:50, 1], color='r', marker='o', label='Golden Eagle')
# last 50 samples = Horned Owls
plt.scatter(X[50:, 0], X[50:, 1], color='b', marker='x', label = "Horned Owl")
plt.title("Bird Classification Sample Data")
plt.xlabel("Wingspan (metres)")
plt.ylabel("Weight (kilograms)")
plt.legend(loc = 'upper left')
plt.xlim([0, 2.5])
plt.ylim([0, 14])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment