My dataset( Network traffic dataset where we do binary classification)-
The shape of X_train and y_train are (45447, 25) (45447,)
The model I am working on-
# fit and evaluate a model
import tensorflow as tf
def evaluate_model(X_train, y_train,X_test,y_test):
X_train = X_train.reshape(45447,25,1)
y_train=y_train.reshape(45447,1)
verbose=0
epochs=10
batch_size = 32
n_timesteps = X_train.shape[0]
n_features= X_train.shape[1]
print(n_timesteps,n_features)
n_outputs = 1
model = Sequential()
model.add(Conv1D(filters=64, kernel_size=3, activation='relu', input_shape=(n_timesteps,n_features)))
model.add(Conv1D(filters=64, kernel_size=3, activation='relu'))
model.add(Dropout(0.5))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(Dense(100, activation='relu'))
model.add(Dense(n_outputs, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
# fit network
#train_data = tf.data.Dataset.from_tensor_slices((X_train, y_train))
#valid_data = tf.data.Dataset.from_tensor_slices((X_test, y_test))
model.fit(X_train, y_train,epochs=10, batch_size=32, verbose=0)
# evaluate model
#_, accuracy = model.evaluate(X_test, y_test, batch_size=batch_size, verbose=0)
# summarize scores
def summarize_results(scores):
print(scores)
m, s = mean(scores), std(scores)
print('Accuracy: %.3f%% (+/-%.3f)' % (m, s))
# run an experiment
def run_experiment(repeats=10):
# load data
# repeat experiment
scores = list()
for r in range(repeats):
score = evaluate_model(X_train, y_train,X_test,y_test)
score = score * 100.0
print('>#%d: %.3f' % (r+1, score))
scores.append(score)
# summarize results
summarize_results(scores)
# run the experiment
run_experiment()
What I have tried-
1)I tried making the pandas data into numpy
2)Reshaped the 2d array to 3d -
X_train = X_train.reshape(45447,25,1)
y_train=y_train.reshape(45447,1,1)
Made the data into tf objects-
train_data = tf.data.Dataset.from_tensor_slices((X_train, y_train)) valid_data = tf.data.Dataset.from_tensor_slices((X_test, y_test))
Still Im unable to run my model..it keeps giving shape errors. Please help me understand the shape to give to model.
