Incompatible shapes


I try to make predictions with keras models but face an issue when I use fit. My goal is to get 30 next minutes prediction on BNB/USDT stock

The error I get is

tensorflow.python.framework.errors_impl.InvalidArgumentError: 2 root error(s) found.
  (0) Invalid argument: Incompatible shapes: [32,30] vs. [32,30,1]
         [[{{node loss/dense_loss/SquaredDifference}}]]
  (1) Invalid argument: Incompatible shapes: [32,30] vs. [32,30,1]
         [[{{node loss/dense_loss/SquaredDifference}}]]

Here’s the code

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, LSTM
from binance.client import Client
import csv
import tensorflow as tf
pd.options.mode.chained_assignment = None

api = {'key':'...','secret':'...'}

# client = Client(api['key'], api['secret'])
# length_data = "2 day"

# klines = client.get_historical_klines("BNBUSDT", Client.KLINE_INTERVAL_1MINUTE, length_data + " UTC")

# with open('./bnbusdt_price_train_test.csv', 'w') as f:
#   writer = csv.writer(f)
#   writer.writerow(['timestamp','open','max','min','close'])

#   for sub in klines:
#     writer.writerow([sub[0], sub[1], sub[2], sub[3], sub[4]])

df = pd.read_csv('./bnbusdt_price_train_test.csv')
df['Date'] = pd.to_datetime(df.timestamp, unit='ms')

y = df['close'].fillna(method='ffill')
y = y.values.reshape(-1, 1)

scaler = MinMaxScaler(feature_range=(0, 1))
scaler =
y = scaler.transform(y)

n_lookback = 60
n_forecast = 30 

X = []
Y = []

for i in range(n_lookback, len(y) - n_forecast + 1):
  X.append(y[i - n_lookback: i])
  Y.append(y[i: i + n_forecast])

X = np.array(X)
Y = np.array(Y)

model = Sequential()
model.add(LSTM(units=50, return_sequences=True, input_shape=(n_lookback, 1)))

model.compile(loss='mean_squared_error', optimizer='adam'), Y, epochs=1, batch_size=32, verbose=2)

The CSV I load up contains :

  • timestamp (ms)
  • open price
  • max price
  • min price
  • close price

I tried to changed my 3d inputs to 2d but got another error on model.add

Do you have any idea ?

Hey, sorry to bump an old thread, did you find a fix for this issue, I currently have the same issue of ‘Incompatible shapes: [11,50,4] vs. [11,50,4,1]’

Could you try to replace input_shape=(n_lookback, 1) with input_shape=(n_lookback) and let us know? Thank you

… I do not exactly know what the data looks like, but the error says there is a mismatch in the provided data shape and the shape …I have a dataset with more than 4000 images and 3 classes, and I’m 192.168.l.254 reusing a code for capsule neural network with 10 classes but I modified it to 3 classes, …Guys. I have to detect the changes that a forget gate has in an lstm cell in feed forwarding data, in order to do this (since simple print functions …