Reputation: 75
I have some trouble with sklearn.cluster.
I`ve prepeared my data to clustering and have few columns with float-type data.
I`ve chek twice, the columns dtype is float64 but when i tried to
df['cluster'] = cluster.fit_predict([df.columns[1:])
I see:
ValueError: could not convert string to float: column_name_1
Last Traceback look like
...
-> return self.fit(X).lables
...
-> X = Self._check_fit_data(X)
...
-> X = check_array(X, accept_sparce='csr', dtype = [np.float, np.float32])
...
-> array = np.array(array, dtype=dtype, order=order, copy=copy)
I tried to convert float to string and back, but it does not work. What should i try to fix this problem? P.S. I use Python 2.7.
Upvotes: 1
Views: 1737
Reputation: 16966
You are trying to fit the column names.
df['cluster'] = cluster.fit_predict([df.columns[1:])
It should be
df['cluster'] = cluster.fit_predict(df.loc[:,1:])
Upvotes: 1