Skip to content

Instantly share code, notes, and snippets.

@matmoody
Last active May 19, 2016 17:47
Show Gist options
  • Save matmoody/ec83a619155e442e752f778866f6f5e5 to your computer and use it in GitHub Desktop.
Save matmoody/ec83a619155e442e752f778866f6f5e5 to your computer and use it in GitHub Desktop.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
iris = pd.read_csv("https://raw.githubusercontent.com/Thinkful-Ed/curric-data-001-data-sets/master/iris/iris.data.csv", names = ['Sepal_l', 'Sepal_w', 'petal_l', 'petal_w', 'class'])
# Plot iris data
plt.scatter(iris['Sepal_l'], iris['Sepal_w'])
plt.xlabel('Sepal length')
plt.ylabel('Sepal Width')
plt.show()
X = iris[['Sepal_l', 'Sepal_w']]
X_random = X.ix[17]
from sklearn.neighbors import NearestNeighbors
# Identify the 10 nearest neighbors
nbrs = NearestNeighbors(n_neighbors=10, algorithm='ball_tree').fit(X)
distances, indices = nbrs.kneighbors(X)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment