Created
December 30, 2019 13:35
-
-
Save ashishpatel26/379a1f14b4f6af0b623ca53ea7b63456 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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