pylablanche / gcForest

Python implementation of deep forest method : gcForest
MIT License
417 stars 193 forks source link

getting Buffer has wrong number of dimensions (expected 1, got 2) error #12

Open uhotspot4 opened 6 years ago

uhotspot4 commented 6 years ago

I get the following error when calling these lines:

gcf = gcForest(shape_1X=6, window=(4)) gcf.fit(X_train, Y_train])

and the dimensions of my features and target are:

[1686 rows x 6 columns] and [1686 rows x 1 columns]

Slicing Sequence...

ValueError Traceback (most recent call last)

in () ----> 1 gcf.fit(df[columns].iloc[:last_train_index], df[['is_attributed']].iloc[:last_train_index]) in fit(self, X, y) 97 raise ValueError('Sizes of y and X do not match.') 98 ---> 99 mgs_X = self.mg_scanning(X, y) 100 _ = self.cascade_forest(mgs_X, y) 101 in mg_scanning(self, X, y) 146 147 for wdw_size in getattr(self, 'window'): --> 148 wdw_pred_prob = self.window_slicing_pred_prob(X, wdw_size, shape_1X, y=y) 149 mgs_pred_prob.append(wdw_pred_prob) 150 in window_slicing_pred_prob(self, X, window, shape_1X, y) 176 else: 177 print('Slicing Sequence...') --> 178 sliced_X, sliced_y = self._window_slicing_sequence(X, window, shape_1X, y=y, stride=stride) 179 180 if y is not None: in _window_slicing_sequence(self, X, window, shape_1X, y, stride) 264 ind_1X = np.arange(np.prod(shape_1X)) 265 inds_to_take = [ind_1X[i:i+window] for i in iter_array] --> 266 sliced_sqce = np.take(X, inds_to_take, axis=1).reshape(-1, window) 267 268 if y is not None: /opt/conda/lib/python3.6/site-packages/numpy/core/fromnumeric.py in take(a, indices, axis, out, mode) 157 [5, 7]]) 158 """ --> 159 return _wrapfunc(a, 'take', indices, axis=axis, out=out, mode=mode) 160 161 /opt/conda/lib/python3.6/site-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds) 50 def _wrapfunc(obj, method, *args, **kwds): 51 try: ---> 52 return getattr(obj, method)(*args, **kwds) 53 54 # An AttributeError occurs if the object does not have /opt/conda/lib/python3.6/site-packages/pandas/core/generic.py in take(self, indices, axis, convert, is_copy, **kwargs) 2246 2247 convert = nv.validate_take(tuple(), kwargs) -> 2248 return self._take(indices, axis=axis, convert=convert, is_copy=is_copy) 2249 2250 def xs(self, key, axis=0, level=None, drop_level=True): /opt/conda/lib/python3.6/site-packages/pandas/core/generic.py in _take(self, indices, axis, convert, is_copy) 2148 new_data = self._data.take(indices, 2149 axis=self._get_block_manager_axis(axis), -> 2150 verify=True) 2151 result = self._constructor(new_data).__finalize__(self) 2152 /opt/conda/lib/python3.6/site-packages/pandas/core/internals.py in take(self, indexer, axis, verify, convert) 4262 new_labels = self.axes[axis].take(indexer) 4263 return self.reindex_indexer(new_axis=new_labels, indexer=indexer, -> 4264 axis=axis, allow_dups=True) 4265 4266 def merge(self, other, lsuffix='', rsuffix=''): /opt/conda/lib/python3.6/site-packages/pandas/core/internals.py in reindex_indexer(self, new_axis, indexer, axis, fill_value, allow_dups, copy) 4144 if axis == 0: 4145 new_blocks = self._slice_take_blocks_ax0(indexer, -> 4146 fill_tuple=(fill_value,)) 4147 else: 4148 new_blocks = [blk.take_nd(indexer, axis=axis, fill_tuple=( /opt/conda/lib/python3.6/site-packages/pandas/core/internals.py in _slice_take_blocks_ax0(self, slice_or_indexer, fill_tuple) 4190 else: 4191 blknos = algos.take_1d(self._blknos, slobj, fill_value=-1, -> 4192 allow_fill=allow_fill) 4193 blklocs = algos.take_1d(self._blklocs, slobj, fill_value=-1, 4194 allow_fill=allow_fill) /opt/conda/lib/python3.6/site-packages/pandas/core/algorithms.py in take_nd(arr, indexer, axis, out, fill_value, mask_info, allow_fill) 1381 func = _get_take_nd_function(arr.ndim, arr.dtype, out.dtype, axis=axis, 1382 mask_info=mask_info) -> 1383 func(arr, indexer, out, fill_value) 1384 1385 if flip_order: pandas/_libs/algos_take_helper.pxi in pandas._libs.algos.take_1d_int64_int64() ValueError: Buffer has wrong number of dimensions (expected 1, got 2)
persistLearning commented 6 years ago

I have met the same problem, which kind of datasets you use? I guess it may have some correlation with the parameter shape_1X. If you slove the problem, could you tell me how to solve it ? Thank you .

persistLearning commented 6 years ago

I have found my problem, I use pandas to read the dataset, the type of X_train is dataframe. It has to transform to ndarray. Hope it can help you!

tecWang commented 6 years ago

I also encountered the same problem. I no longer report an error after converting df to ndarray.

nikhildec31 commented 4 years ago

I also encountered the same error however, its not getting resolved. i am guessing it might be due to shape or window. Please suggest me Screenshot (18)

Htrismegistos commented 4 years ago

same with bokeh. I start from df to CoulumnDataSource i have two checkbox and two dropdown. at certain combinations it throws this error when all the marks are the same at dropbox and there is no selection from checkbox. if i have only one dropbox there is no error. it comes in jupiter notebook and bokeh serve as well.

it must be something with pandas...