Aleksandar Venchev
Aleksandar Venchev

Reputation: 7

Keras 3D input to 1D output

I am trying to model tabular data combining cross sectional with a time series component, essentially using the last n records of my X to predict a single Y value.

I am using the lastest versions of both tensorflow and keras

def build_model(input_shape):
    model = Sequential([
    Dense(units = (len(input_variables) * 2) - 1
                 , activation= activation_func
                 , input_shape=input_shape
                 , kernel_initializer = ini_method),      
    Dense(1)])
    optimizer = Adam(lr)
  
    model.compile(
                loss='mse',
                optimizer=optimizer,
                metrics=['mae', 'mse'])
    return model

model = build_model(n,m)

model.fit(X,y)

X is shaped (k,n,m)

y is shaped (k,1)

This is the model I am using. The input shape I give it is (n,m). However I am getting a (n,1) output when I want a (,1) output.

What am I missing ?

Upvotes: 0

Views: 865

Answers (1)

Andrew Holmgren
Andrew Holmgren

Reputation: 1275

You need to flatten your (n, m) dimensions, either beforehand or with the Keras flatten layer. E.g.

model = Sequential([
    Flatten(),
    Dense(units = (len(input_variables) * 2) - 1
                 , activation= activation_func
                 , input_shape=input_shape
                 , kernel_initializer = ini_method),      
    Dense(1)])

Upvotes: 1

Related Questions