Data Science Asked by vanetoj on November 5, 2021
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
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
Answered by Itachi on November 5, 2021
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]]
Answered by Swapnil Pote on November 5, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP