title: Can I send callbacks to a KerasClassifier?
body: <p>I want the classifier to run faster and stop early if the patience reaches the number I set. In the following code it does 10 iterations of fitting the model.</p>
  
  <pre><code>import numpy
  import pandas
  from keras.models import Sequential
  from keras.layers import Dense
  from keras.layers import Dropout
  from keras.wrappers.scikit_learn import KerasClassifier
  from keras.callbacks import EarlyStopping, ModelCheckpoint
  from keras.constraints import maxnorm
  from keras.optimizers import SGD
  from sklearn.model_selection import cross_val_score
  from sklearn.preprocessing import LabelEncoder
  from sklearn.model_selection import StratifiedKFold
  from sklearn.preprocessing import StandardScaler
  from sklearn.pipeline import Pipeline
  # fix random seed for reproducibility
  seed = 7
  numpy.random.seed(seed)
  # load dataset
  dataframe = pandas.read_csv("sonar.csv", header=None)
  dataset = dataframe.values
  # split into input (X) and output (Y) variables
  X = dataset[:,0:60].astype(float)
  Y = dataset[:,60]
  # encode class values as integers
  encoder = LabelEncoder()
  encoder.fit(Y)
  encoded_Y = encoder.transform(Y)
  
  calls=[EarlyStopping(monitor='acc', patience=10), ModelCheckpoint('C:/Users/Nick/Data Science/model', monitor='acc', save_best_only=True, mode='auto', period=1)]
  
  def create_baseline(): 
      # create model
      model = Sequential()
      model.add(Dropout(0.2, input_shape=(33,)))
      model.add(Dense(33, init='normal', activation='relu', W_constraint=maxnorm(3)))
      model.add(Dense(16, init='normal', activation='relu', W_constraint=maxnorm(3)))
      model.add(Dense(122, init='normal', activation='softmax'))
      # Compile model
      sgd = SGD(lr=0.1, momentum=0.8, decay=0.0, nesterov=False)
      model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
      return model
  
  numpy.random.seed(seed)
  estimators = []
  estimators.append(('standardize', StandardScaler()))
  estimators.append(('mlp', KerasClassifier(build_fn=create_baseline, nb_epoch=300, batch_size=16, verbose=0, callbacks=calls)))
  pipeline = Pipeline(estimators)
  kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=seed)
  results = cross_val_score(pipeline, X, encoded_Y, cv=kfold)
  print("Baseline: %.2f%% (%.2f%%)" % (results.mean()*100, results.std()*100))
  </code></pre>
  
  <p>Here is the resulting error-</p>
  
  <pre><code>RuntimeError: Cannot clone object &lt;keras.wrappers.scikit_learn.KerasClassifier object at 0x000000001D691438&gt;, as the constructor does not seem to set parameter callbacks
  </code></pre>
  
  <p>I changed the cross_val_score in the following-</p>
  
  <pre><code>numpy.random.seed(seed)
  estimators = []
  estimators.append(('standardize', StandardScaler()))
  estimators.append(('mlp', KerasClassifier(build_fn=create_baseline, nb_epoch=300, batch_size=16, verbose=0, callbacks=calls)))
  pipeline = Pipeline(estimators)
  kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=seed)
  results = cross_val_score(pipeline, X, encoded_Y, cv=kfold, fit_params={'callbacks':calls})
  print("Baseline: %.2f%% (%.2f%%)" % (results.mean()*100, results.std()*100))
  </code></pre>
  
  <p>and now I get this error-</p>
  
  <pre><code>ValueError: need more than 1 value to unpack
  </code></pre>
  
  <p><a href="http://machinelearningmastery.com/dropout-regularization-deep-learning-models-keras/" rel="noreferrer">This code came from here</a>. The code is by far the most accurate I've used so far. The problem is that there is no defined <code>model.fit()</code> anywhere in the code. It also takes forever to fit. The <code>fit()</code> operation occurs at the <code>results = cross_val_score(...)</code> and there's no parameters to throw a callback in there.</p>
  
  <p>How do I go about doing this?
  Also, how do I run the model trained on a test set?</p>
  
  <p>I need to be able to save the trained model for later use...</p>