0
$\begingroup$

I am a beginner in TensorFlow as well as in AI. I am basically from Pharma background and learning AI from scratch.

I have data with 5038 input (Float64) and 826 output (Categorical - Multi Labels in each column). I have utilized one-hot encoding but the neural network tackles only one output at a time.

[1]How to process all 826 output (which give 6689 one-hot output) at once in a neural network. Here is the code that I am using. [2] I am getting only 31% accuracy. I get this accuracy just in the second epoch. From second or third epoch onwards accuracy and other parameters become constant. Am I doing the wrong code here?

dataset = df.values
X = dataset[:,0:5038]/220
Y_smile = dataset[:,5038 :5864]

from sklearn.preprocessing import OneHotEncoder
enc = OneHotEncoder(handle_unknown='ignore')
enc.fit(Y_smile)
OneHotEncoder(handle_unknown='ignore')
enc.categories_
Y = enc.transform(Y_smile).toarray()
print(Y,Y.shape, Y.dtype)

from sklearn.model_selection import train_test_split
X_train, X_val_and_test, Y_train, Y_val_and_test = train_test_split(X, Y, test_size=0.3)
X_val, X_test, Y_val, Y_test = train_test_split(X_val_and_test, Y_val_and_test, test_size=0.5)

import numpy as np
X_train = np.asarray(X_train).astype(np.float64)
X_val = np.asarray(X_val).astype(np.float64)
X_test = np.asarray(X_test).astype(np.float64)

filepath = "bestmodelweights.hdf5"
checkpoint = [tf.keras.callbacks.ModelCheckpoint(filepath, monitor='val_accuracy', mode='auto', save_best_only=True, Save_weights_only = True, verbose = 1), 
              tf.keras.callbacks.EarlyStopping(monitor='val_accuracy', patience=5, verbose =1)]

model = tf.keras.Sequential([
                             tf.keras.layers.Dense(1024, activation='relu', input_shape=(5038,)),
                             tf.keras.layers.Dense(524, activation='relu'),
                             tf.keras.layers.Dense(524, activation='relu'),
                             tf.keras.layers.Dense(1024, activation='relu'),
                             tf.keras.layers.Dense(1024, activation='relu'),
                             tf.keras.layers.Dense(1024, activation='relu'),
                             tf.keras.layers.Dense(1024, activation='relu'),
                             tf.keras.layers.Dense(1024, activation='relu'),
                             tf.keras.layers.Dense(1024, activation='relu'),
                             tf.keras.layers.Dense(1024, activation='relu'),
                             tf.keras.layers.Dense(1024, activation='relu'),
                             tf.keras.layers.Dense(1024, activation='relu'),
                             tf.keras.layers.Dense(1024, activation='relu'),
                             tf.keras.layers.Dense(1024, activation='relu'),                        
                             tf.keras.layers.Dense(6689, activation= 'softmax')])

model.compile(optimizer=tf.keras.optimizers.Adam(), loss=tf.keras.losses.BinaryCrossentropy(from_logits = True), metrics=['accuracy'])

hist = model.fit(X_train, Y_train, epochs= 200, callbacks=[checkpoint],validation_data=(X_val, Y_val))
$\endgroup$

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.