I'm running KMeans
to cluster the data like
from sklearn.cluster import KMeans
kmeans = KMeans(n_clusters=N, random_state=0).fit(X)
Centers = kmeans.cluster_centers_
Now, I need to use placeholder
and use the code like the following
X = tf.placeholder(tf.float32, shape=(None, num_features))
kmeans = KMeans(n_clusters=N, random_state=0).fit(X)
Centers = kmeans.cluster_centers_
However, it dose not work. Is there any equivalent way in tensorflow (tensorflow.compat.v1
) that I can use both KMeans
and placeholder
?
CodePudding user response:
The error comes from confusion about what a placeholder is.
Roughly speaking, these are tf objects thought to be there as a promise to get a variable.
Your X
has a shape, but it is an empty object. In order to fit a model you have to give it something containing data, and this is not the case. If you really want to use a tensorflow object (and I advise against it) you have to put data into it, for example using tf.variable
.