Я пытаюсь реализовать алгоритм BIRCH для данных в формате CSV. Но я застрял с ошибкой
from sklearn.cluster import Birch
import pandas as pd
import numpy as np
X=[[2, 1], [0.3, 1], [0.5, 1], [0, -1], [0.3, -1], [-5, -1],[0.5, -1],[2, -1],[1, -1],[1.5, -1],[1, -1],[1, -1],[1.2, -1]]
df=pd.DataFrame(X,columns=['x','y'])
csv_data=df.to_csv()
data=np.reshape(csv_data,-1, 1)
brc = Birch(n_clusters=None)
brc.fit(data)
brc.predict(data)
после запуска brc.fit(data)
, я получил ошибку
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-67-8fe5a979a3f6> in <module>
----> 1 brc.fit(data)
~/anaconda3/lib/python3.7/site-packages/sklearn/cluster/birch.py in fit(self, X, y)
445 """
446 self.fit_, self.partial_fit_ = True, False
--> 447 return self._fit(X)
448
449 def _fit(self, X):
~/anaconda3/lib/python3.7/site-packages/sklearn/cluster/birch.py in _fit(self, X)
448
449 def _fit(self, X):
--> 450 X = check_array(X, accept_sparse='csr', copy=self.copy)
451 threshold = self.threshold
452 branching_factor = self.branching_factor
~/anaconda3/lib/python3.7/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
519 "Reshape your data either using array.reshape(-1, 1) if "
520 "your data has a single feature or array.reshape(1, -1) "
--> 521 "if it contains a single sample.".format(array))
522
523 # in the future np.flexible dtypes will be handled like object dtypes
ValueError: Expected 2D array, got 1D array instead:
array=[',x,y\n0,2.0,1\n1,0.3,1\n2,0.5,1\n3,0.0,-1\n4,0.3,-1\n5,-5.0,-1\n6,0.5,-1\n7,2.0,-1\n8,1.0,-1\n9,1.5,-1\n10,1.0,-1\n11,1.0,-1\n12,1.2,-1\n'].
Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
Та же ошибка, когда я пытался загрузить CSV-файл. Может кто-нибудь помочь мне решить эту проблему?