-1

I am solving a multi-class classification problem.The data set looks like below :

|---------------------|------------------|----------------------|------------------|
|      feature 1      |     feature 3    |   feature 4          |     feature 2    |
|---------------------|------------------|------------------------------------------
|          1.302      |       102.987    |      1.298           |     99.8         |
|---------------------|------------------|----------------------|------------------|
|---------------------|------------------|----------------------|------------------|
|          1.318      |       102.587    |      1.998           |     199.8        |
|---------------------|------------------|----------------------|------------------|

The 4 features are floats and my target variable classes are either 1,2, or 3 .When I build the follow model and train it takes so long to converge (24 hours and still running )

I used a keras model like below :

def create_model(optimizer='adam', init='uniform'):
    # create model
    if verbose: print("**Create model with optimizer: %s; init: %s" % (optimizer, init) )
    model = Sequential()
    model.add(Dense(16, input_dim=X.shape[1], kernel_initializer=init, activation='relu'))
    model.add(Dense(8, kernel_initializer=init, activation='relu'))
    model.add(Dense(4, kernel_initializer=init, activation='relu'))
    model.add(Dense(1, kernel_initializer=init, activation='sigmoid'))
    # Compile model
    model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])
    return model

fitting the model

best_epochs = 200
best_batch_size = 5
best_init = 'glorot_uniform'
best_optimizer = 'rmsprop'
verbose=0
model_pred = KerasClassifier(build_fn=create_model, optimizer=best_optimizer, init=best_init, epochs=best_epochs, batch_size=best_batch_size, verbose=verbose)
model_pred.fit(X_train,y_train)

I followed the tutorial here: https://www.kaggle.com/stefanbergstein/keras-deep-learning-on-titanic-data

and also a fast ai model like below :

cont_names = [ 'feature1', 'feature2', 'feature3', 'feature4']
procs = [FillMissing, Categorify, Normalize]
test = TabularList.from_df(test,cont_names=cont_names, procs=procs)
data = (TabularList.from_df(train, path='.', cont_names=cont_names, procs=procs)
                        .random_split_by_pct(valid_pct=0.2, seed=43)
                        .label_from_df(cols = dep_var)
                        .add_test(test, label=0)
                        .databunch())

learn = tabular_learner(data, layers=[1000, 200, 15], metrics=accuracy, emb_drop=0.1, callback_fns=ShowGraph)

I followed the tutorial below

https://medium.com/@nikkisharma536/applying-deep-learning-on-tabular-data-for-regression-and-classification-problems-1e5f80743259

print(X_train.shape,y_train.shape,X_test.shape,y_test.shape)
(138507, 4) (138507, 1) (34627, 4) (34627, 1)

Not sure why both the models are taking so long to run .is there any error in my inputs? Any help is appreciated.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Ricky
  • 2,662
  • 5
  • 25
  • 57
  • 1
    How many training examples do you have? How many epochs? Could you provide the code block with the fit method? – alan.elkin May 01 '20 at 03:55
  • @alan.elkin I added it in the question .Thanks – Ricky May 01 '20 at 04:35
  • How many classes you have ( i guess 3 based on above description). If it is multi-class classification, why are you using `binary_crossentropy` (need to use `categorical_crossentropy` or the `sparse_categorical_crossentropy` based on your target label) – Vishnuvardhan Janapati May 01 '20 at 13:47

1 Answers1

4

With 200 epochs and over 138k training examples (and almost 35k test examples), you are dealing with a total of 34626800 (~35M) examples shown to the network. Those are big numbers. Assuming that you are using your CPU for training, this may take several hours, even days, depending on your hardware. One thing you could do is lower the number of epochs to see if you have and acceptable model earlier.

alan.elkin
  • 954
  • 1
  • 10
  • 19