When I run model.predict(##)
, I get the result nan
. I also get this for calculating the loss function. This is what my code looks like:
import tensorflow as tf
import numpy as np
from tensorflow import keras
print(tf.__version__)
# Build a simple Sequential model
model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[2])])
# Compile the model
model.compile(optimizer='sgd', loss='mean_squared_error')
# Declare model inputs and outputs for training
x_train = np.loadtxt("combined_data.txt")
y_train = np.loadtxt("admit_data.txt")
# Train the model
model.fit(x_train, y_train, epochs=500)
prediction = np.array([[160, 160]])
print(np.shape(prediction))
# Make a prediction
print(model.predict(prediction))
# Evaluate the model
loss = model.evaluate(x_train, y_train)
print(f'Loss: {loss}')
And this is what some of the training data looks like: x_train:
163 164
152 161
159 158
164 146
163 154
163 131
152 150
141 155
147 157
142 168
139 156
151 151
144 160
134 157
158 143
167 133
And then my y_train values are either 0, 50, or 100, and cannot be anything else. I would expect a prediction somewhere from 0 to 100, but instead I get NAN (not a number)
nan
values).