0
$\begingroup$

Is there a way to add a layer which includes my preprocessing steps in this sequential model.For example

model.add(LabelEncoder.transform(X_train['gender'],X_train['grade']),scaler(X_train))

How to include this step in the create model definition?

def create_model(optimizer='adagrad',
             kernel_initializer='glorot_uniform', 
             dropout=0.2):
model = Sequential()
model.add(Dense(64,activation='relu',kernel_initializer=kernel_initializer))
model.add(Dropout(dropout))
model.add(Dense(1,activation='sigmoid',kernel_initializer=kernel_initializer))

model.compile(loss='binary_crossentropy',optimizer=optimizer, metrics=['accuracy'])

return model

Help in this regard is very much appreciated.

$\endgroup$
  • 1
    $\begingroup$ Welcome to SE.DataScience! Even if there is such solution, generally it is not a good practice, since a single instance may be fed to the model multiple times, thus it will be pre-processed multiple times instead of only once. Therefore, it is better to keep all the pre-processing out of the model. $\endgroup$ – Esmailian Apr 6 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.