I am getting (loss: nan - accuracy: 0.0000e+00) for all epochs after training the model
I made a simple model to train my data set which consists of (210 samples and each sample consists of a numpy array of 22 values)
and x_trian
and y_trian
look like:
and this is my simple code:
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Activation, Dense
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.metrics import categorical_crossentropy
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.utils import shuffler
from google.colab import files
uploaded = files.upload()
import io
dset = pd.read_csv(io.BytesIO(uploaded['1-210.csv']))
y= dset.Readernumber
x=dset.drop('Readername',axis=1)
#the split ratio of 80:20. The 20% testing data set is represented by the 0.2 at the end.
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)
x_train= np.asarray(x_train).astype('float32')
y_train = np.asarray(y_train).astype('float32')
y_train, x_train = shuffle(y_train, x_train)
#create the model #input_shape=(23,)
model = Sequential([
Dense(units=4,input_shape=(22,), activation='relu'),
Dense(units=16, activation='relu'),
Dense(units=10, activation='softmax')
])
#get the model ready for training is call the compile() function on it.
model.compile(optimizer=Adam(learning_rate=0.0001), loss='sparse_categorical_crossentropy', metrics=['accuracy'])
#train it using the fit() function.
model.fit(x_train, y_train, epochs=5)
And this is what I'm getting for all the epochs :
I will be grateful to anyone who can help me!
Topic keras tensorflow deep-learning machine-learning
Category Data Science