python - reshape while converting Pandas Dataframe to numpy array -


i have pandas dataframe, has 4 rows , n columns, out taking 1 column using feature classifier. shown below

0    [1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0] 1    [0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1] 2    [0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0] 3    [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0] 

this column list of 16 binary encoded features.

but when feed classifier, below error comes up

traceback (most recent call last):       clf.fit(x,y)       x, y = check_x_y(x, y, 'csr')       ensure_min_features, warn_on_dtype, estimator)       array = np.array(array, dtype=dtype, order=order, copy=copy) valueerror: setting array element sequence. 

i suppose error because fit method wants nxm matrix, while shape gets is

(4,) 

so basically,

i want try convert shape(4,) shape(4,16)

i tried below functions:

x = np.asarray(train_data['presence_vector']) x.reshape((4,16)) x = train_data['presence_vector'].values x.reshape((4,16)) x = train_data['presence_vector'].as_matrix() x.reshape((4,16)) 

none of worked.

should have tried usual way. if there better solution below

reshaped=[] l in x:     reshaped.append(l)  x_new=np.array(reshaped) print(x_new.shape) (4, 16) 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -