Skip to content

Instantly share code, notes, and snippets.

@cshjin
Created August 11, 2015 05:09
Show Gist options
  • Save cshjin/7eb0b4bb353be9af7935 to your computer and use it in GitHub Desktop.
Save cshjin/7eb0b4bb353be9af7935 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 28 15:28:15 2015
"""
from sklearn.cluster import KMeans
import numpy as np
import pandas
dataset = np.array([1, 4, 5, 6, 9])
km = KMeans(n_clusters=3)
km.fit(dataset.reshape(-1, 1))
df = pandas.DataFrame(pandas.Series(dataset), pandas.Series(km.labels_)).reset_index()
print df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment