i tried to do grid search for finding optimal params.
i write some similar code to this one: https://github.com/fchollet/keras/blob/bb626c120ea56b35b3fde9057877df461af0b02b/examples/mnist_sklearn_wrapper.py
but i have two X, and one Y, which is different from this example(one X, one Y).
i tried to use
validator.fit([x1,x2],Y)
but it showed an error that:
ValueError: Found arrays with inconsistent numbers of samples: [ 2 2500]
i re-check the training data. without the grid search, it can run very well.
so i suspect the fit method cannot receive multiple inputs.
what is the solution, and am i missed something?
Please make sure that the boxes below are checked before you submit your issue. Thank you!
@ymcui Have you found the solution? I also encountered the same problem. It seems that the validator.fit method cannot realize that there are multiple inputs.
@judyweiying not yet :(
Same problem for me... I guess that GridSearch from Sklearn cannot handle multiple inputs...
Same problem
Maybe this issue could be solved the same way suggested here: https://github.com/fchollet/keras/issues/2715
I'll try
I have the same problem. I want to apply a grid search in a network with two inputs, but the fit operation of scikit wants a numpy array as input but the fit operation of keras wants a list of numpy arrays, one per input of the network. It seems that up until now it is imposible to apply a grid search with a network with more than an input.
I am having the same problem. Have you found a solution yet?
Same here. Trying to work out how to do grid search with Scikit using GridSearchCV, but it seems the fit() only accepts one input, whereas my model has several. Tried to work out if I could numpy.vstack() the inputs into one feed, but then I do not know how to unstack them into separate feeds to the network Inputs() with the reshape function in Keras as suggested in #2715.
One can simply change a little bit the keras.wrapper.scikit_learn. In https://github.com/fchollet/keras/blob/master/keras/wrappers/scikit_learn.py, the class takes a numpy array as x, and then we split the columns into a list of numpy, and then feed the keras network. just three lines, Done! This works for me.
@guanzi0629 Thanks for your feedback! Can you share that bit of code too?
@guanzi0629 Would also be interested!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.
I would this code also
I am facing the same issue. Any update on the issue will be appreciated.
I have the same problem, is there any chance this could be patched in master?
Same here, the link provided by @guanzi0629 is empty.
The link is the code for the function scikit_learn.py https://github.com/keras-team/keras/blob/master/keras/wrappers/scikit_learn.py
I wrote the change suggested by @guanzi0629 , it makes the cross_val_score() work but I haven't tested it properly for other cases :
in fit() from BaseWrapper , line 117
x0 = np.array([x[i][0] for i in range (x.shape[0])])
x1 = np.array([x[i][1] for i in range (x.shape[0])])
history = self.model.fit([x0,x1], y, **fit_args)
The idea is that you have to change the shape of your input : let's say you have 300 samples and two inputs, one with 200 features and one with 10 features. The input shape for the scikit functions has to be (nb_sample, nb_features) so you will pass an x with shape (300,2), and then in the wrapper transform this x so that it becomes [ (300,200,1) , (300,10,1) ] .
I applied the changes suggested by @guanzi0629 but gave me this erroe:
raise TypeError("Error converting %s to a TensorShape: %s." % (arg_name, e))
TypeError: Error converting shape to a TensorShape: int() argument must be a string, a bytes-like object or a number, not 'tuple'.
Anyone who has solved the problem please???
Is there any update with this thread?
Same error, a solution would be much appreciated
There is no solution to this problem
According to https://keras.io/scikit-learn-api/
face the same problem
Here a workaround to use GridSearch and Keras model with multiple inputs: https://stackoverflow.com/questions/56824968/grid-search-for-keras-with-multiple-inputs/62512554#62512554
Most helpful comment
@guanzi0629 Thanks for your feedback! Can you share that bit of code too?