I am trying to cluster data using kmeans clustering algorithm. I am using tensorflow for this purpose. Here is the code.
import tensorflow as tf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
def input_fn():
return tf.constant(df.as_matrix(),
tf.float32, df.shape), None
# input file
file = 'data-tf-aml.csv'
# Order
# CdSccpAdd,CgSccpAdd, IMSI, Units size
df = pd.read_csv(file, names=['Cd Sccp Add', 'Cg Sccp Add', 'IMSI', 'Units size'])
tf.logging.set_verbosity(tf.logging.ERROR)
kmeans = tf.contrib.factorization.KMeansClustering(
num_clusters=4, relative_tolerance=0.0001)
# _ = kmeans.train(input_fn=input_fn)
#run a TF graph to get result
kmeans.predict(input_fn, predict_keys=None,hooks=None,checkpoint_path=None,yield_single_examples=True)
trains = kmeans.train(input_fn,hooks=None,steps=None,max_steps=None,saving_listeners=None)
clusters = kmeans.cluster_centers()
dist=kmeans.transform(input_fn)
predict=kmeans.predict(input_fn)
I want a scatter plot for this data. I tried matplotlib, but it returns :
TypeError: 'KMeansClustering' object is not iterable
Comments
Post a Comment