Can we automatically chose k value in k-means algorithm?
This is a known problem of automatic clustering, how to choose / adapt the number of clusters so it represents the &quot;real&quot; clusters.
Hierarchical clustering is more helpful in this regard. For algorithms like K-means this is not so easy and research has tried various approaches to determine the optimum number of clusters (eg employing Information-Theoretic criteria like Akaike information criterion - AIC).
An overview in given in wikipedia article and references therein.

Determining the number of clusters in a data set, a quantity often
labelled k as in the k-means algorithm, is a frequent problem in data
clustering, and is a distinct issue from the process of actually
solving the clustering problem.
[..]The correct choice of k is often ambiguous, with interpretations
depending on the shape and scale of the distribution of points in a
data set and the desired clustering resolution of the user. In
addition, increasing k without penalty will always reduce the amount
of error in the resulting clustering, to the extreme case of zero
error if each data point is considered its own cluster (i.e., when k
equals the number of data points, n). Intuitively then, the optimal
choice of k will strike a balance between maximum compression of the
data using a single cluster, and maximum accuracy by assigning each
data point to its own cluster. If an appropriate value of k is not
apparent from prior knowledge of the properties of the data set, it
must be chosen somehow. There are several categories of methods for
making this decision.