vecxoz / vecstack

Python package for stacking (machine learning technique)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

N-dimensional input (stacking for convolutional nets)

rohan-dot opened this issue · comments

Hi,
I tried to do stacking by using kerasClassifier with a cnn but i get this error
ValueError: Found array with dim 4. Estimator expected <= 2.

This is my code for the cnn

`def model1():
model = Sequential()
model.add(Conv2D(16, (3, 3), activation='relu', padding="same", input_shape=(train_files.shape[1:])))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))

model.add(Conv2D(64, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())  
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy',
          optimizer='rmsprop',
          metrics=['accuracy'])`

Your neural net architecture is OK. This behavior is a result of inner data checking procedure performed by vecstack. Such behavior is expected because according to scikit-learn convention input arrays should be 2-dimensional.

Of course it would be nice to have ability to stack some convolutional nets. So I created a workaround which makes it possible to pass N-dimensional arrays. It is available only in functional API (i.e. vecstack.stacking function).

You can reinstall patched version directly from github branch:

  • use pip3 for Python 3
  • remove --user option if vecstack was installed for all users

pip install --user --upgrade --force-reinstall --no-deps https://github.com/vecxoz/vecstack/archive/n_dim_input.zip

You can return to stable version anytime you want:

pip install --user --upgrade --force-reinstall --no-deps vecstack

Branch n_dim_input was merged into master (#20).