'using k-means with a placeholder as an input
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?
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Oscar |
