Skip to content

Instantly share code, notes, and snippets.

@vihar
Last active January 28, 2018 12:48
Show Gist options
  • Save vihar/fe40534fbb5416062be65e8f99f83e36 to your computer and use it in GitHub Desktop.
Save vihar/fe40534fbb5416062be65e8f99f83e36 to your computer and use it in GitHub Desktop.
from sklearn import datasets
from sklearn.neighbors import KNeighborsClassifier
# Load iris dataset from sklearn
iris = datasets.load_iris()
# Declare an of the KNN classifier class with the value with neighbors.
knn = KNeighborsClassifier(n_neighbors=6)
# Fit the model with training data and target values
knn.fit(iris['data'], iris['target'])
# Provide data whose class labels are to be predicted
X = [
[5.9, 1.0, 5.1, 1.8],
[3.4, 2.0, 1.1, 4.8],
]
# Prints the data provided
print(X)
# Store predicted class labels of X
prediction = knn.predict(X)
# Prints the predicted class labels of X
print(prediction)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment