Reputation: 300
I have a pandas dataframe X_train
with 733999 samples and 5 features.
model = Squential()
model.add(Conv2D(filters = 32, kernel_size = (5,5),padding = 'Same',
activation ='relu', input_shape = (?,?)))
This is the first layer where I am having trouble. All the tutorials have used image and they are just passing in the height, width and channel as the parameter of input_shape. I am having trouble to give the input shape in case of pandas dataframe. Any help is really appreciated.
Upvotes: 1
Views: 2338
Reputation: 376
This is an example on how you can use a CNN with your data
I still do not recommend this type of network for the data that you have
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Reshape
import pandas as pd
import numpy as np
## Dummy data
data = {'0': [1, 2, 3], '1': [3, 4, 3], '2':[0,1, 3], '3':[0,1,3], '4':[0,1,3], '5':[0,1,3]}
X_train = pd.DataFrame(data=data)
model = Sequential()
model.add(Reshape((1,X_train.shape[1],1)))
model.add(Conv2D(filters = 32, kernel_size = (1,5),padding = 'Same',
activation ='relu', input_shape = (1,X_train.shape[1],1)))
model.add(MaxPooling2D(pool_size = (1,6), strides=(1,2)))
model.add(Flatten())
model.add(Dense (500, activation='relu'))
model.add(Dense (1, activation='relu'))
model.compile(loss='binary_crossentropy', optimizer='adam',
metrics=['accuracy'])
## Training and testing with dummy data just to prove that it's working
model.fit(np.array(X_train), np.array([0,1,1]), nb_epoch=4, validation_data=(np.array(X_train), np.array([0,1,1])))
Upvotes: 1