Skip to content

Instantly share code, notes, and snippets.

@ashishpatel26
Created December 30, 2019 13:35
Show Gist options
  • Save ashishpatel26/379a1f14b4f6af0b623ca53ea7b63456 to your computer and use it in GitHub Desktop.
Save ashishpatel26/379a1f14b4f6af0b623ca53ea7b63456 to your computer and use it in GitHub Desktop.
from sklearn.cluster import KMeans
import pandas as pd
data = {'one': [1., 2., 3., 4., 3., 2., 1.], 'two': [4., 3., 2., 1., 2., 3., 4.]}
data = pd.DataFrame(data)
n_clusters = 2
for col in data.columns:
kmeans = KMeans(n_clusters=n_clusters)
X = data[col].reshape(-1, 1)
kmeans.fit(X)
print "{}: {}".format(col, kmeans.predict(X))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment