Skip to content

Instantly share code, notes, and snippets.

@yindia
Created May 24, 2017 15:08
Show Gist options
  • Save yindia/2576f4eb6701df56a8ac96e2747a47c0 to your computer and use it in GitHub Desktop.
Save yindia/2576f4eb6701df56a8ac96e2747a47c0 to your computer and use it in GitHub Desktop.
Need Help to feed data To Tensor
Action Drama Thriller Comedy Romance Adventure Animation History Sci-Fi Family Crime Horror Mystery Fantasy Documentary Sports War Suspense Musical Biography Social Mythology Classic Devotional Satire Dance Children Noir Period CRIME Magic Short Film ROMANCE DEVOTIONAL Patriotic International Music Festival Theatre Cricket Concert Screening ACTION Party Bollywood Romantic Adult Classical Religious Psychological Spiritual Music Political Zombie-Comedy Romantic-Comedy Action-Comedy EDM Fusion Music Rock Pop Western Kids Screenings Black / Dark Comedy Fiction Entertainment Period Emotional Offbeat Adaptation Friendship Love Mature Supernatural Sports Costume HISTORY Art General Special Interest FAMILY COMEDY DRAMA Obscure Teenage Black Comedy SOCIAL Classics Short MYSTERY Urban THRILLER ROMANCE COMEDY Love Triangle Science fiction Biopic Spirituality Performing Arts Westren Filmnoir Costume Drama Stunt Historical Science Fiction Crime Thriller Thiller ACTION COMEDY Romance Comedy Road Movie Arts & Culture
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
from __future__ import print_function
import numpy as np
import pandas as pd
from sklearn.cluster import KMeans, DBSCAN, MiniBatchKMeans
import tensorflow as tf
MATRIX_SIZE = 110#features 110
DATA_SET_URL = "./movie_data/input_data.csv"
CLUSTER = 50
BATCH_SIZE = 1000
def read_data():
Xtr = []
Xtr = np.array(pd.read_csv(DATA_SET_URL, header=None, skiprows=1),dtype="float")
Xtr = Xtr.astype("float")
return Xtr#Xtr#tf.cast(Xtr, tf.float32) #tf.constant(Xtr)
def placeholder_inputs():
points = tf.placeholder(tf.float32, [None,110])
return points
def fill_feed_dict(data_set,points):
#input_feed = data_set.next_batch(batch_size)
feed_dict = {
points : data_set
}
return feed_dict
def kmeanTF(points):
centroids = tf.Variable(tf.slice(tf.random_shuffle(points), [0, 0], [CLUSTER, -1]))
points_expanded = tf.expand_dims(points, 0)
centroids_expanded = tf.expand_dims(centroids, 1)
distances = tf.reduce_sum(tf.square(tf.sub(points_expanded, centroids_expanded)), 2)
assignments = tf.argmin(distances, 0)
means = []
for c in xrange(CLUSTER):
means.append(tf.reduce_mean(
tf.gather(points,
tf.reshape(
tf.where(
tf.equal(assignments, c)
),[1,-1])
),reduction_indices=[1]))
new_centroids = tf.concat(0, means)
update_centroids = tf.assign(centroids, new_centroids)
return update_centroids, centroids, assignments
def run_training():
data_set = read_data();
points = placeholder_inputs();
feed_dict = fill_feed_dict(data_set,points)
assignment_values,centroid_value= kmeanTF(points);
init = tf.initialize_all_variables()
# Create a session for running Ops on the Graph.
sess = tf.InteractiveSession()
# Run the Op to initialize the variables.
sess.run(init)
for step in xrange(5):
[assignment_values] = sess.run([assignments],feed_dict)
print("assignment_values" + "\n",assignment_values)
run_training()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment