Scikit-learn: How to run KMeans on a one-dimensional array?

You have many samples of 1 feature, so you can reshape the array to (13,876, 1) using numpy’s reshape:

from sklearn.cluster import KMeans
import numpy as np
x = np.random.random(13876)

km = KMeans()
km.fit(x.reshape(-1,1))  # -1 will be calculated to be 13876 here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)