Skip to content

Instantly share code, notes, and snippets.

@vihar
Last active May 11, 2018 18:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vihar/7918710745532891acb854876152aefa to your computer and use it in GitHub Desktop.
Save vihar/7918710745532891acb854876152aefa to your computer and use it in GitHub Desktop.
# Importing Modules
from sklearn import datasets
from sklearn.cluster import KMeans
# Loading dataset
iris_df = datasets.load_iris()
# Declaring Model
model = KMeans(n_clusters=3)
# Fitting Model
model.fit(iris_df.data)
# Predicitng a single input
predicted_label = model.predict([[7.2, 3.5, 0.8, 1.6]])
# Prediction on the entire data
all_predictions = model.predict(iris_df.data)
# Printing Predictions
print(predicted_label)
print(all_predictions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment