0
$\begingroup$

I am not sure why I am receiving this value error. Additionally, I haven't found a tutorial that explicitly talks about the appropriateness of size of filters and kernel. I would appreciate some input and some links. I am predicting the next to the last or last column.

Here is my code:

import pandas as pd
import keras
from keras import Input, layers , Model
from sklearn.model_selection import train_test_split
from keras.layers import Dropout


input_tensor=Input(shape=(6,))
x= layers.Conv1D(filters=128,kernel_size=18, padding='same', activation='relu')(input_tensor)
#x=layers.MaxPooling1D(5)(x)
#x = Dropout(0.5)(x)

x= layers.Conv1D(256,5, activation='relu')(x)
#x = Dropout(0.4)(x)
#x= layers.Dense(4, activation='relu')(x)
#x = Dropout(0.2)(x)
x= layers.Conv1D(256,5, activation='relu')(x)
x=layers.MaxPooling1D(5)(x)

x = Dropout(0.3)(x)
#x= layers.Dense(16,1, activation='relu')(x)

callbacks_list=[
        keras.callbacks.EarlyStopping(monitor='acc',
                                      patience=3,),
                                      keras.callbacks.ModelCheckpoint(
                                              filepath= 'C:/Users/vtodorova/results3/APIFunctional.py',
                                              monitor='accuracy',
                                              save_best_only=True),
                                              keras.callbacks.ReduceLROnPlateau(
                                                      factor=0.1, patience=10,)]


model.compile(optimizer='RMSprop', loss='mse', metrics=['accuracy'])
#callbacks=callbacks_list
model.fit(X1_train, y1_train, epochs=3, batch_size=256, verbose=1)
model.fit(X2_train, y2_train, epochs=3, batch_size=256, verbose=1)

score1=model.evaluate(X1_train, y1_train)
score2=model.evaluate(X2_train, y2_train)

output_tensor=layers.Dense(1)(x)

model=Model(input_tensor, output_tensor)

Here is the head of the data. The names of the columns and the columns got a little misplaced when I copied and pasted, but I hope its ok.

AutoLeadID  leadage  leadstatustypeid  hasCob  hasSRE 
0   695746319        5                 1           0                 0   
1   695746320        5                 1           0                 0   
2   695746321        5                 1           0                 0   
3   695746322        5                 1           0                 0   
4   695746323        5                 1           0                 0   

   hasSRC   hasCRE                                                hasCRPC  
0                0                      0                         0  
1                0                      0                         0  
2                0                      0                         0  
3                0                      0                         0  
4                0                      0                         0  
$\endgroup$
1
  • 1
    $\begingroup$ Can you type up the exact error, and tell us to which line it refers? $\endgroup$ Commented Jun 25, 2019 at 22:57

2 Answers 2

0
$\begingroup$

After running your code & the major issue found out is the lack of proper mentioning of input shape.

In your case insisted of passing shape=(6,) try to pass shape=(6,1) and make sure your data should in the following format.

x = [[695746319], [5], [1], [0], [0], [0], [0]]
$\endgroup$
0
$\begingroup$

Can you give exact error, can't solve without that!!

There are 2 problems, the first your input shape should be input_tensor=Input(shape=(6, 1)) as it was throwing this error:

input 0 is incompatible with layer conv1d_31: expected ndim=3, found ndim=2

Solving this, I'm sensing problem with 3rd Conv1D, here it goes

Input has shape 6, and with padding = same, the output is 6.

Second convolution has output of shape 2 by formula out_shape = (in_shape - kernel_size + 2*padding)/stride +1 (valid padding)

3rd convolution has kernel size 5 with input shape 2, that should give negative shape error. This is an impossible task mathematically. so either reduce the size of kernel or remove this layer. Also, you need to modify pooling layer as well, it will throw same error

$\endgroup$
2
  • $\begingroup$ so how do you resolve the second error? and where could i read about that stuff - the formulas of how input size changes and all that? thanks! $\endgroup$
    – vanetoj
    Commented Jun 26, 2019 at 14:30
  • $\begingroup$ you can remove 2nd layer all together, or do same padding for if you desire it very much. The formula for change in shape follow: quora.com/… $\endgroup$
    – Itachi
    Commented Jun 26, 2019 at 17:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.