title: TypeError: predict() missing 1 required positional argument: 'X'
body: <p>I'm trying to use scikit-learn in conjunction with Keras (Theano backend) in order to optimize some hyperparameters of my neural network, however I keep getting the same error (as stated in the title). I'm not sure how to get around it. Here is my code for importing the dataset:</p>
  
  <pre><code>import pandas as pd
  
  df=pd.read_csv(r'C:\Users\Vikram\OneDrive\Documents\Videos\Documents\PERTH-USD_JPY_D.csv')
  print(df.head())
  </code></pre>
  
  <p>Code for changing the backend to Theano:</p>
  
  <pre><code>import theano
  import os
  os.environ['KERAS_BACKEND'] = 'theano'
  import keras
  # Using Theano backend.
  </code></pre>
  
  <p>Preliminary stuff:</p>
  
  <pre><code>from keras import regularizers
  from keras import layers
  from keras.constraints import maxnorm
  
  import pylab as pl
  import numpy as np
  import scipy.optimize as opt
  from sklearn import preprocessing
  import matplotlib.pyplot as plt
  from sklearn.preprocessing import MinMaxScaler
  </code></pre>
  
  <p>Defining inputs and output:</p>
  
  <pre><code>X = df[['Ask High', 'Bid Low', 'Ask Low', 'Bid Average', 'Ask Average']]
  X = X.values
  
  min_max_scaler = MinMaxScaler()
  feature_mtx = min_max_scaler.fit_transform(X)
  print(X.shape)
  
  
  y = df[['Bid High']]
  y=y.values
  y=y.ravel()
  print(y.shape)
  </code></pre>
  
  <p>Split into training and testing data:</p>
  
  <pre><code>from sklearn.model_selection import train_test_split 
  X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.1, random_state=4) 
  
  X_train, y_train = np.array(X_train), np.array(y_train)
  print ('Train set:', X_train.shape, y_train.shape) 
  print ('Test set:', X_test.shape, y_test.shape) 
  </code></pre>
  
  <p>Reshaping inputs to 3D vectors for compatibility with LSTM:</p>
  
  <pre><code>X_train = np.reshape(X_train, (X_train.shape[0], 1, X_train.shape[1]))
  X_test = np.reshape(X_test, (X_test.shape[0], 1, X_test.shape[1]))
  print(X_train.shape)
  print(X_test.shape)
  </code></pre>
  
  <p>Build the neural network:</p>
  
  <pre><code>def model_build(rate=0.1, max_value=3):
    model = keras.Sequential()
    model.add(layers.LSTM(180, activation='tanh', input_shape = (X_train.shape[1], X_train.shape[2]), return_sequences=True))
    model.add(layers.LSTM(100, activation='tanh', bias_regularizer=regularizers.l1(0.01), return_sequences=True))
    model.add(layers.Dropout(rate=0.1))
    model.add(layers.LSTM(100, activation='tanh', return_sequences=True))
    model.add(layers.Dense(100, kernel_initializer='random_normal', bias_regularizer=regularizers.l1(0.01), kernel_constraint=maxnorm(max_value=3), activation='relu'))
    model.add(layers.Flatten())
    model.add(layers.Dense(1, kernel_initializer='random_uniform', activation='linear'))
  
    model.compile(optimizer=keras.optimizers.Adam(), loss='mean_squared_error', metrics=['mean_absolute_error'])
    return model
  </code></pre>
  
  <p>Use KerasRegressor wrapper for scikit-learn:</p>
  
  <pre><code>from keras.wrappers.scikit_learn import KerasRegressor
  model_2 = KerasRegressor(build_fn=model_build, epochs=3, batch_size=10, verbose=0)
  </code></pre>
  
  <p>Hyperparameter optimization algorithm:</p>
  
  <pre><code>from sklearn.model_selection import RandomizedSearchCV
  max_value = [1, 2, 3, 4, 5]
  rate = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5]
  param_grid = dict(max_value=max_value, rate=rate)
  rand=RandomizedSearchCV(model_2, param_grid, cv=3)
  rand.fit(X_train, y_train)
  print("Best: %f using %s" % (rand.best_score_, rand.best_params_))
  yhat=rand.predict(X_test)
  </code></pre>
  
  <p>Regression metric:</p>
  
  <pre><code>from sklearn.metrics import explained_variance_score
  expvar=explained_variance_score(y_test, yhat, multioutput='uniform average')
  print(expvar)
  </code></pre>
  
  <p>And this is my error where <code>yhat</code> is defined:</p>
  
  <pre><code>TypeError: predict() missing 1 required positional argument: 'X'
  </code></pre>
  
  <p>EDIT:
  Here is the full traceback for the error:</p>
  
  <pre><code>Traceback (most recent call last):
  
    File "&lt;ipython-input-1-5f9c97171748&gt;", line 1, in &lt;module&gt;
      runfile('C:/Users/Vikram/.spyder-py3/temp.py', wdir='C:/Users/Vikram/.spyder-py3')
  
    File "C:\Users\Vikram\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
      execfile(filename, namespace)
  
    File "C:\Users\Vikram\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
      exec(compile(f.read(), filename, 'exec'), namespace)
  
    File "C:/Users/Vikram/.spyder-py3/temp.py", line 71, in &lt;module&gt;
      yhat=rand.predict(X_test)
  
    File "C:\Users\Vikram\Anaconda3\lib\site-packages\sklearn\utils\metaestimators.py", line 116, in &lt;lambda&gt;
      out = lambda *args, **kwargs: self.fn(*args, **kwargs)
  
  TypeError: predict() missing 1 required positional argument: 'X'
  </code></pre>