title: Scale data for LSTM models in time series
body: <p>I am developing an LSTM model to predict energy consumption and would like to scale my data. To do this, I applied transformations to the function that splits the dataset into training and test, as shown in the code below.</p>
  <pre><code># split a univariate dataset into train/test sets
  def split_dataset(data, input_scaler,output_scaler):
      # split into standard weeks
      train, test = data[4:-189], data[-190:-1]
      # restructure into windows of weekly data
      train = array(split(train, len(train)/7))
      test = array(split(test, len(test)/7))
      # scale inputs
      # fit scaler
      input_scaler.fit(train)
      # transform training dataset
      train = input_scaler.transform(train)
      # transform test dataset
      train = input_scaler.transform(train)
      # reshape 1d arrays to 2d arrays
      test = test.reshape(len(test), 1)
      test = test.reshape(len(test), 1)
      # fit scaler on training dataset
      output_scaler.fit(test)
      # transform training dataset
      test = output_scaler.transform(test)
      # transform test dataset
      test = output_scaler.transform(test)
      return train, test
  </code></pre>
  <p>I also have this function that allows to evaluate the model several times from the input and output scalers:</p>
  <pre><code> # evaluate model multiple times with given input and output scalers
  def repeated_evaluation(input_scaler, output_scaler, n_repeats=30):
      # get dataset
      train, test = split_dataset(data,input_scaler, output_scaler)
      # repeated evaluation of model
      results = list()
      for _ in range(n_repeats):
          test_mse = evaluate_model(train, test)
          print('&gt;%.3f' % test_mse)
          results.append(test_mse)
      return results
  </code></pre>
  <p>Then when I run this code :</p>
  <pre><code># normalized inputs
  results_normalized_inputs = repeated_evaluation(MinMaxScaler(), StandardScaler())
  # standardized inputs
  results_standardized_inputs = repeated_evaluation(StandardScaler(), StandardScaler())
  # summarize results
  #print('Unscaled: %.3f (%.3f)' % (mean(results_unscaled_inputs), std(results_unscaled_inputs)))
  print('Normalized: %.3f (%.3f)' % (mean(results_normalized_inputs), std(results_normalized_inputs)))
  print('Standardized: %.3f (%.3f)' % (mean(results_standardized_inputs), std(results_standardized_inputs)))
  # plot results
  results = [results_normalized_inputs, results_standardized_inputs]
  labels = ['normalized', 'standardized']
  pyplot.boxplot(results, labels=labels)
  pyplot.show()
  </code></pre>
  <p>Then i get this error message:</p>
  <pre><code>ValueError                                Traceback (most recent call last)
  c:\Users\Utilizador\Desktop\hello_ds\hydra_daily.ipynb Cell 15' in &lt;module&gt;
        1 # unscaled inputs
        2 #results_unscaled_inputs = repeated_evaluation(None, StandardScaler())
        3 # normalized inputs
  ----&gt; 4 results_normalized_inputs = repeated_evaluation(MinMaxScaler(), StandardScaler())
        5 # standardized inputs
        6 results_standardized_inputs = repeated_evaluation(StandardScaler(), StandardScaler())
  
  c:\Users\Utilizador\Desktop\hello_ds\hydra_daily.ipynb Cell 13' in repeated_evaluation(input_scaler, output_scaler, n_repeats)
        2 def repeated_evaluation(input_scaler, output_scaler, n_repeats=30):
        3     # get dataset
  ----&gt; 4     train, test = split_dataset(data,input_scaler, output_scaler)
        5     # repeated evaluation of model
        6     results = list()
  
  c:\Users\Utilizador\Desktop\hello_ds\hydra_daily.ipynb Cell 6' in split_dataset(data, input_scaler, output_scaler)
        4 train, test = data[4:-189], data[-190:-1]
        5 # restructure into windows of weekly data
        6 #train = array(split(train, len(train)/7))
        7 #test = array(split(test, len(test)/7))
        8 # scale inputs
        9 # fit scaler
  ---&gt; 10 input_scaler.fit(train)
       11 # transform training dataset
       12 train = input_scaler.transform(train)
  
  ValueError: Found array with 0 sample(s) (shape=(0, 7)) while a minimum of 1 is required by MinMaxScaler.
  </code></pre>
  <p>Can someone help me to solve this error?
  Thanks</p>