I am new to NN and Keras. I have tried this tutorial from DeepLizard and followed it until the lady showed the first training results ~30min in. I followed the steps exactly except the lines with 'shuffle' since that was not how it is supposed to be used (to my knowledge). Here is my code:
import numpy as np
import random as random
from random import randint
from sklearn.preprocessing import MinMaxScaler
from random import shuffle
train_labels = []
train_samples = []
for i in range(50):
random_younger = randint(13,64)
train_samples.append(random_younger)
train_labels.append(1)
random_older = randint(65,100)
train_samples.append(random_older)
train_labels.append(0)
for i in range (1000):
random_younger = randint(13,64)
train_samples.append(random_younger)
train_labels.append(0)
random_older = randint(65,100)
train_samples.append(random_older)
train_labels.append(1)
train_samples = np.array(train_samples)
train_labels = np.array(train_labels)
shuffle(train_samples)
shuffle(train_labels)
scaler = MinMaxScaler(feature_range = (0,1))
scaled_train_samples = scaler.fit_transform(train_samples. reshape(-1,1))
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
model = Sequential([Dense(units=16, input_shape=(1,), activation='relu'),
Dense(units=32, activation='relu'),
Dense(units=2, activation='softmax')])
model.summary()
model.compile(optimizer=Adam(learning_rate=0.0001),loss='sparse_categorical_crossentropy', metrics=['accuracy'])
model.fit(x=scaled_train_samples, y=train_labels, batch_size=5, epochs=30, shuffle=True, verbose=2)
My NN doesn't learn staying at 50% accuracy all the time. I tried to vary the #of layers and epochs, I have checked the data types and structure. Can someone help with the first in my life minimal example? Thanks!