Tensorflow - Nan loss and constant accuracy when training











up vote
0
down vote

favorite












as the title says, I am trying to train a neural network to predict outcomes, and I can't figure out what is wrong with my model. I keep getting the exact same accuracy level, and the loss is Nan. I'm so confused... I have looked at other similar questions and still can't seem to get it working. My code for the model and training is below:



import numpy as np
import pandas as pd
import tensorflow as tf
import urllib.request as request
import matplotlib.pyplot as plt
from FlowersCustom import get_MY_data

def get_data():
IRIS_TRAIN_URL = "http://download.tensorflow.org/data/iris_training.csv"
IRIS_TEST_URL = "http://download.tensorflow.org/data/iris_test.csv"

names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'species']
train = pd.read_csv(IRIS_TRAIN_URL, names=names, skiprows=1)
test = pd.read_csv(IRIS_TEST_URL, names=names, skiprows=1)

# Train and test input data
Xtrain = train.drop("species", axis=1)
Xtest = test.drop("species", axis=1)

# Encode target values into binary ('one-hot' style) representation
ytrain = pd.get_dummies(train.species)
ytest = pd.get_dummies(test.species)

return Xtrain, Xtest, ytrain, ytest


def create_graph(hidden_nodes):
# Reset the graph
tf.reset_default_graph()

# Placeholders for input and output data
X = tf.placeholder(shape=Xtrain.shape, dtype=tf.float64, name='X')
y = tf.placeholder(shape=ytrain.shape, dtype=tf.float64, name='y')

# Variables for two group of weights between the three layers of the network
print(Xtrain.shape, ytrain.shape)
W1 = tf.Variable(np.random.rand(Xtrain.shape[1], hidden_nodes), dtype=tf.float64)
W2 = tf.Variable(np.random.rand(hidden_nodes, ytrain.shape[1]), dtype=tf.float64)

# Create the neural net graph
A1 = tf.sigmoid(tf.matmul(X, W1))
y_est = tf.sigmoid(tf.matmul(A1, W2))

# Define a loss function
deltas = tf.square(y_est - y)
loss = tf.reduce_sum(deltas)

# Define a train operation to minimize the loss
# optimizer = tf.train.GradientDescentOptimizer(0.005)
optimizer = tf.train.AdamOptimizer(0.001)
opt = optimizer.minimize(loss)

return opt, X, y, loss, W1, W2, y_est


def train_model(hidden_nodes, num_iters, opt, X, y, loss, W1, W2, y_est):
# Initialize variables and run session
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
losses =

# Go through num_iters iterations
for i in range(num_iters):
sess.run(opt, feed_dict={X: Xtrain, y: ytrain})
local_loss = sess.run(loss, feed_dict={X: Xtrain.values, y: ytrain.values})
losses.append(local_loss)
weights1 = sess.run(W1)
weights2 = sess.run(W2)

y_est_np = sess.run(y_est, feed_dict={X: Xtrain.values, y: ytrain.values})
correct = [estimate.argmax(axis=0) == target.argmax(axis=0)
for estimate, target in zip(y_est_np, ytrain.values)]
acc = 100 * sum(correct) / len(correct)

if i % 10 == 0:
print('Epoch: %d, Accuracy: %.2f, Loss: %.2f' % (i, acc, local_loss))

print("loss (hidden nodes: %d, iterations: %d): %.2f" % (hidden_nodes, num_iters, losses[-1]))
sess.close()
return weights1, weights2


def test_accuracy(weights1, weights2):
X = tf.placeholder(shape=Xtest.shape, dtype=tf.float64, name='X')
y = tf.placeholder(shape=ytest.shape, dtype=tf.float64, name='y')
W1 = tf.Variable(weights1)
W2 = tf.Variable(weights2)
A1 = tf.sigmoid(tf.matmul(X, W1))
y_est = tf.sigmoid(tf.matmul(A1, W2))

# Calculate the predicted outputs
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
y_est_np = sess.run(y_est, feed_dict={X: Xtest, y: ytest})

# Calculate the prediction accuracy
correct = [estimate.argmax(axis=0) == target.argmax(axis=0)
for estimate, target in zip(y_est_np, ytest.values)]
accuracy = 100 * sum(correct) / len(correct)
print('final accuracy: %.2f%%' % accuracy)


def get_inputs_and_outputs(train, test, output_column_name):
Xtrain = train.drop(output_column_name, axis=1)
Xtest = test.drop(output_column_name, axis=1)
ytrain = pd.get_dummies(getattr(train, output_column_name))
ytest = pd.get_dummies(getattr(test, output_column_name))

return Xtrain, Xtest, ytrain, ytest




if __name__ == '__main__':

train, test = get_MY_data('output')

Xtrain, Xtest, ytrain, ytest = get_inputs_and_outputs(train, test, 'output')#get_data()
# Xtrain, Xtest, ytrain, ytest = get_data()

hidden_layers = 10
num_epochs = 500


opt, X, y, loss, W1, W2, y_est = create_graph(hidden_layers)
w1, w2 = train_model(hidden_layers, num_epochs, opt, X, y, loss, W1, W2, y_est)
# test_accuracy(w1, w2)


Here is a screenshot of what the training is printing out:
enter image description here



And this is a screenshot of the Pandas Dataframe that I am using for the input data (5 columns of floats):
enter image description here



And finally, here is the Pandas Dataframe that I am using for the expected outputs (1 column of either -1 or 1):
enter image description here










share|improve this question






















  • When I run your code using the get_data function the programme works as expected. I suggest looking at what is returned by the get_MY_data and get_inputs_and_outputs functions for problems to start with.
    – Chris
    Nov 8 at 7:26










  • Did you try normalizing the feature values?
    – jeevaa_v
    Nov 8 at 8:13










  • @Chris I know, I am trying to use my own data instead of the iris dataset, and for some reason whenever I do that everything stops working.
    – user3492226
    Nov 8 at 19:00










  • @jeevaa_v I did normalize the data. Previously, it was like > 10,000 so I took the logs of each datapoint
    – user3492226
    Nov 8 at 19:00










  • @user3492226, yes sorry, no doubt you were aware of that! If the loss wasn't NaN from the first epoch I'd suspect an exploding gradient, but it that seems less likely under the circumstances. Your data, as presented in the question, is of a notably different form to the Iris dataset. Can you share the code you've used to convert it to the Iris format?
    – Chris
    Nov 8 at 19:30















up vote
0
down vote

favorite












as the title says, I am trying to train a neural network to predict outcomes, and I can't figure out what is wrong with my model. I keep getting the exact same accuracy level, and the loss is Nan. I'm so confused... I have looked at other similar questions and still can't seem to get it working. My code for the model and training is below:



import numpy as np
import pandas as pd
import tensorflow as tf
import urllib.request as request
import matplotlib.pyplot as plt
from FlowersCustom import get_MY_data

def get_data():
IRIS_TRAIN_URL = "http://download.tensorflow.org/data/iris_training.csv"
IRIS_TEST_URL = "http://download.tensorflow.org/data/iris_test.csv"

names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'species']
train = pd.read_csv(IRIS_TRAIN_URL, names=names, skiprows=1)
test = pd.read_csv(IRIS_TEST_URL, names=names, skiprows=1)

# Train and test input data
Xtrain = train.drop("species", axis=1)
Xtest = test.drop("species", axis=1)

# Encode target values into binary ('one-hot' style) representation
ytrain = pd.get_dummies(train.species)
ytest = pd.get_dummies(test.species)

return Xtrain, Xtest, ytrain, ytest


def create_graph(hidden_nodes):
# Reset the graph
tf.reset_default_graph()

# Placeholders for input and output data
X = tf.placeholder(shape=Xtrain.shape, dtype=tf.float64, name='X')
y = tf.placeholder(shape=ytrain.shape, dtype=tf.float64, name='y')

# Variables for two group of weights between the three layers of the network
print(Xtrain.shape, ytrain.shape)
W1 = tf.Variable(np.random.rand(Xtrain.shape[1], hidden_nodes), dtype=tf.float64)
W2 = tf.Variable(np.random.rand(hidden_nodes, ytrain.shape[1]), dtype=tf.float64)

# Create the neural net graph
A1 = tf.sigmoid(tf.matmul(X, W1))
y_est = tf.sigmoid(tf.matmul(A1, W2))

# Define a loss function
deltas = tf.square(y_est - y)
loss = tf.reduce_sum(deltas)

# Define a train operation to minimize the loss
# optimizer = tf.train.GradientDescentOptimizer(0.005)
optimizer = tf.train.AdamOptimizer(0.001)
opt = optimizer.minimize(loss)

return opt, X, y, loss, W1, W2, y_est


def train_model(hidden_nodes, num_iters, opt, X, y, loss, W1, W2, y_est):
# Initialize variables and run session
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
losses =

# Go through num_iters iterations
for i in range(num_iters):
sess.run(opt, feed_dict={X: Xtrain, y: ytrain})
local_loss = sess.run(loss, feed_dict={X: Xtrain.values, y: ytrain.values})
losses.append(local_loss)
weights1 = sess.run(W1)
weights2 = sess.run(W2)

y_est_np = sess.run(y_est, feed_dict={X: Xtrain.values, y: ytrain.values})
correct = [estimate.argmax(axis=0) == target.argmax(axis=0)
for estimate, target in zip(y_est_np, ytrain.values)]
acc = 100 * sum(correct) / len(correct)

if i % 10 == 0:
print('Epoch: %d, Accuracy: %.2f, Loss: %.2f' % (i, acc, local_loss))

print("loss (hidden nodes: %d, iterations: %d): %.2f" % (hidden_nodes, num_iters, losses[-1]))
sess.close()
return weights1, weights2


def test_accuracy(weights1, weights2):
X = tf.placeholder(shape=Xtest.shape, dtype=tf.float64, name='X')
y = tf.placeholder(shape=ytest.shape, dtype=tf.float64, name='y')
W1 = tf.Variable(weights1)
W2 = tf.Variable(weights2)
A1 = tf.sigmoid(tf.matmul(X, W1))
y_est = tf.sigmoid(tf.matmul(A1, W2))

# Calculate the predicted outputs
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
y_est_np = sess.run(y_est, feed_dict={X: Xtest, y: ytest})

# Calculate the prediction accuracy
correct = [estimate.argmax(axis=0) == target.argmax(axis=0)
for estimate, target in zip(y_est_np, ytest.values)]
accuracy = 100 * sum(correct) / len(correct)
print('final accuracy: %.2f%%' % accuracy)


def get_inputs_and_outputs(train, test, output_column_name):
Xtrain = train.drop(output_column_name, axis=1)
Xtest = test.drop(output_column_name, axis=1)
ytrain = pd.get_dummies(getattr(train, output_column_name))
ytest = pd.get_dummies(getattr(test, output_column_name))

return Xtrain, Xtest, ytrain, ytest




if __name__ == '__main__':

train, test = get_MY_data('output')

Xtrain, Xtest, ytrain, ytest = get_inputs_and_outputs(train, test, 'output')#get_data()
# Xtrain, Xtest, ytrain, ytest = get_data()

hidden_layers = 10
num_epochs = 500


opt, X, y, loss, W1, W2, y_est = create_graph(hidden_layers)
w1, w2 = train_model(hidden_layers, num_epochs, opt, X, y, loss, W1, W2, y_est)
# test_accuracy(w1, w2)


Here is a screenshot of what the training is printing out:
enter image description here



And this is a screenshot of the Pandas Dataframe that I am using for the input data (5 columns of floats):
enter image description here



And finally, here is the Pandas Dataframe that I am using for the expected outputs (1 column of either -1 or 1):
enter image description here










share|improve this question






















  • When I run your code using the get_data function the programme works as expected. I suggest looking at what is returned by the get_MY_data and get_inputs_and_outputs functions for problems to start with.
    – Chris
    Nov 8 at 7:26










  • Did you try normalizing the feature values?
    – jeevaa_v
    Nov 8 at 8:13










  • @Chris I know, I am trying to use my own data instead of the iris dataset, and for some reason whenever I do that everything stops working.
    – user3492226
    Nov 8 at 19:00










  • @jeevaa_v I did normalize the data. Previously, it was like > 10,000 so I took the logs of each datapoint
    – user3492226
    Nov 8 at 19:00










  • @user3492226, yes sorry, no doubt you were aware of that! If the loss wasn't NaN from the first epoch I'd suspect an exploding gradient, but it that seems less likely under the circumstances. Your data, as presented in the question, is of a notably different form to the Iris dataset. Can you share the code you've used to convert it to the Iris format?
    – Chris
    Nov 8 at 19:30













up vote
0
down vote

favorite









up vote
0
down vote

favorite











as the title says, I am trying to train a neural network to predict outcomes, and I can't figure out what is wrong with my model. I keep getting the exact same accuracy level, and the loss is Nan. I'm so confused... I have looked at other similar questions and still can't seem to get it working. My code for the model and training is below:



import numpy as np
import pandas as pd
import tensorflow as tf
import urllib.request as request
import matplotlib.pyplot as plt
from FlowersCustom import get_MY_data

def get_data():
IRIS_TRAIN_URL = "http://download.tensorflow.org/data/iris_training.csv"
IRIS_TEST_URL = "http://download.tensorflow.org/data/iris_test.csv"

names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'species']
train = pd.read_csv(IRIS_TRAIN_URL, names=names, skiprows=1)
test = pd.read_csv(IRIS_TEST_URL, names=names, skiprows=1)

# Train and test input data
Xtrain = train.drop("species", axis=1)
Xtest = test.drop("species", axis=1)

# Encode target values into binary ('one-hot' style) representation
ytrain = pd.get_dummies(train.species)
ytest = pd.get_dummies(test.species)

return Xtrain, Xtest, ytrain, ytest


def create_graph(hidden_nodes):
# Reset the graph
tf.reset_default_graph()

# Placeholders for input and output data
X = tf.placeholder(shape=Xtrain.shape, dtype=tf.float64, name='X')
y = tf.placeholder(shape=ytrain.shape, dtype=tf.float64, name='y')

# Variables for two group of weights between the three layers of the network
print(Xtrain.shape, ytrain.shape)
W1 = tf.Variable(np.random.rand(Xtrain.shape[1], hidden_nodes), dtype=tf.float64)
W2 = tf.Variable(np.random.rand(hidden_nodes, ytrain.shape[1]), dtype=tf.float64)

# Create the neural net graph
A1 = tf.sigmoid(tf.matmul(X, W1))
y_est = tf.sigmoid(tf.matmul(A1, W2))

# Define a loss function
deltas = tf.square(y_est - y)
loss = tf.reduce_sum(deltas)

# Define a train operation to minimize the loss
# optimizer = tf.train.GradientDescentOptimizer(0.005)
optimizer = tf.train.AdamOptimizer(0.001)
opt = optimizer.minimize(loss)

return opt, X, y, loss, W1, W2, y_est


def train_model(hidden_nodes, num_iters, opt, X, y, loss, W1, W2, y_est):
# Initialize variables and run session
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
losses =

# Go through num_iters iterations
for i in range(num_iters):
sess.run(opt, feed_dict={X: Xtrain, y: ytrain})
local_loss = sess.run(loss, feed_dict={X: Xtrain.values, y: ytrain.values})
losses.append(local_loss)
weights1 = sess.run(W1)
weights2 = sess.run(W2)

y_est_np = sess.run(y_est, feed_dict={X: Xtrain.values, y: ytrain.values})
correct = [estimate.argmax(axis=0) == target.argmax(axis=0)
for estimate, target in zip(y_est_np, ytrain.values)]
acc = 100 * sum(correct) / len(correct)

if i % 10 == 0:
print('Epoch: %d, Accuracy: %.2f, Loss: %.2f' % (i, acc, local_loss))

print("loss (hidden nodes: %d, iterations: %d): %.2f" % (hidden_nodes, num_iters, losses[-1]))
sess.close()
return weights1, weights2


def test_accuracy(weights1, weights2):
X = tf.placeholder(shape=Xtest.shape, dtype=tf.float64, name='X')
y = tf.placeholder(shape=ytest.shape, dtype=tf.float64, name='y')
W1 = tf.Variable(weights1)
W2 = tf.Variable(weights2)
A1 = tf.sigmoid(tf.matmul(X, W1))
y_est = tf.sigmoid(tf.matmul(A1, W2))

# Calculate the predicted outputs
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
y_est_np = sess.run(y_est, feed_dict={X: Xtest, y: ytest})

# Calculate the prediction accuracy
correct = [estimate.argmax(axis=0) == target.argmax(axis=0)
for estimate, target in zip(y_est_np, ytest.values)]
accuracy = 100 * sum(correct) / len(correct)
print('final accuracy: %.2f%%' % accuracy)


def get_inputs_and_outputs(train, test, output_column_name):
Xtrain = train.drop(output_column_name, axis=1)
Xtest = test.drop(output_column_name, axis=1)
ytrain = pd.get_dummies(getattr(train, output_column_name))
ytest = pd.get_dummies(getattr(test, output_column_name))

return Xtrain, Xtest, ytrain, ytest




if __name__ == '__main__':

train, test = get_MY_data('output')

Xtrain, Xtest, ytrain, ytest = get_inputs_and_outputs(train, test, 'output')#get_data()
# Xtrain, Xtest, ytrain, ytest = get_data()

hidden_layers = 10
num_epochs = 500


opt, X, y, loss, W1, W2, y_est = create_graph(hidden_layers)
w1, w2 = train_model(hidden_layers, num_epochs, opt, X, y, loss, W1, W2, y_est)
# test_accuracy(w1, w2)


Here is a screenshot of what the training is printing out:
enter image description here



And this is a screenshot of the Pandas Dataframe that I am using for the input data (5 columns of floats):
enter image description here



And finally, here is the Pandas Dataframe that I am using for the expected outputs (1 column of either -1 or 1):
enter image description here










share|improve this question













as the title says, I am trying to train a neural network to predict outcomes, and I can't figure out what is wrong with my model. I keep getting the exact same accuracy level, and the loss is Nan. I'm so confused... I have looked at other similar questions and still can't seem to get it working. My code for the model and training is below:



import numpy as np
import pandas as pd
import tensorflow as tf
import urllib.request as request
import matplotlib.pyplot as plt
from FlowersCustom import get_MY_data

def get_data():
IRIS_TRAIN_URL = "http://download.tensorflow.org/data/iris_training.csv"
IRIS_TEST_URL = "http://download.tensorflow.org/data/iris_test.csv"

names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'species']
train = pd.read_csv(IRIS_TRAIN_URL, names=names, skiprows=1)
test = pd.read_csv(IRIS_TEST_URL, names=names, skiprows=1)

# Train and test input data
Xtrain = train.drop("species", axis=1)
Xtest = test.drop("species", axis=1)

# Encode target values into binary ('one-hot' style) representation
ytrain = pd.get_dummies(train.species)
ytest = pd.get_dummies(test.species)

return Xtrain, Xtest, ytrain, ytest


def create_graph(hidden_nodes):
# Reset the graph
tf.reset_default_graph()

# Placeholders for input and output data
X = tf.placeholder(shape=Xtrain.shape, dtype=tf.float64, name='X')
y = tf.placeholder(shape=ytrain.shape, dtype=tf.float64, name='y')

# Variables for two group of weights between the three layers of the network
print(Xtrain.shape, ytrain.shape)
W1 = tf.Variable(np.random.rand(Xtrain.shape[1], hidden_nodes), dtype=tf.float64)
W2 = tf.Variable(np.random.rand(hidden_nodes, ytrain.shape[1]), dtype=tf.float64)

# Create the neural net graph
A1 = tf.sigmoid(tf.matmul(X, W1))
y_est = tf.sigmoid(tf.matmul(A1, W2))

# Define a loss function
deltas = tf.square(y_est - y)
loss = tf.reduce_sum(deltas)

# Define a train operation to minimize the loss
# optimizer = tf.train.GradientDescentOptimizer(0.005)
optimizer = tf.train.AdamOptimizer(0.001)
opt = optimizer.minimize(loss)

return opt, X, y, loss, W1, W2, y_est


def train_model(hidden_nodes, num_iters, opt, X, y, loss, W1, W2, y_est):
# Initialize variables and run session
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
losses =

# Go through num_iters iterations
for i in range(num_iters):
sess.run(opt, feed_dict={X: Xtrain, y: ytrain})
local_loss = sess.run(loss, feed_dict={X: Xtrain.values, y: ytrain.values})
losses.append(local_loss)
weights1 = sess.run(W1)
weights2 = sess.run(W2)

y_est_np = sess.run(y_est, feed_dict={X: Xtrain.values, y: ytrain.values})
correct = [estimate.argmax(axis=0) == target.argmax(axis=0)
for estimate, target in zip(y_est_np, ytrain.values)]
acc = 100 * sum(correct) / len(correct)

if i % 10 == 0:
print('Epoch: %d, Accuracy: %.2f, Loss: %.2f' % (i, acc, local_loss))

print("loss (hidden nodes: %d, iterations: %d): %.2f" % (hidden_nodes, num_iters, losses[-1]))
sess.close()
return weights1, weights2


def test_accuracy(weights1, weights2):
X = tf.placeholder(shape=Xtest.shape, dtype=tf.float64, name='X')
y = tf.placeholder(shape=ytest.shape, dtype=tf.float64, name='y')
W1 = tf.Variable(weights1)
W2 = tf.Variable(weights2)
A1 = tf.sigmoid(tf.matmul(X, W1))
y_est = tf.sigmoid(tf.matmul(A1, W2))

# Calculate the predicted outputs
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
y_est_np = sess.run(y_est, feed_dict={X: Xtest, y: ytest})

# Calculate the prediction accuracy
correct = [estimate.argmax(axis=0) == target.argmax(axis=0)
for estimate, target in zip(y_est_np, ytest.values)]
accuracy = 100 * sum(correct) / len(correct)
print('final accuracy: %.2f%%' % accuracy)


def get_inputs_and_outputs(train, test, output_column_name):
Xtrain = train.drop(output_column_name, axis=1)
Xtest = test.drop(output_column_name, axis=1)
ytrain = pd.get_dummies(getattr(train, output_column_name))
ytest = pd.get_dummies(getattr(test, output_column_name))

return Xtrain, Xtest, ytrain, ytest




if __name__ == '__main__':

train, test = get_MY_data('output')

Xtrain, Xtest, ytrain, ytest = get_inputs_and_outputs(train, test, 'output')#get_data()
# Xtrain, Xtest, ytrain, ytest = get_data()

hidden_layers = 10
num_epochs = 500


opt, X, y, loss, W1, W2, y_est = create_graph(hidden_layers)
w1, w2 = train_model(hidden_layers, num_epochs, opt, X, y, loss, W1, W2, y_est)
# test_accuracy(w1, w2)


Here is a screenshot of what the training is printing out:
enter image description here



And this is a screenshot of the Pandas Dataframe that I am using for the input data (5 columns of floats):
enter image description here



And finally, here is the Pandas Dataframe that I am using for the expected outputs (1 column of either -1 or 1):
enter image description here







python tensorflow machine-learning artificial-intelligence






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 6:33









user3492226

205




205












  • When I run your code using the get_data function the programme works as expected. I suggest looking at what is returned by the get_MY_data and get_inputs_and_outputs functions for problems to start with.
    – Chris
    Nov 8 at 7:26










  • Did you try normalizing the feature values?
    – jeevaa_v
    Nov 8 at 8:13










  • @Chris I know, I am trying to use my own data instead of the iris dataset, and for some reason whenever I do that everything stops working.
    – user3492226
    Nov 8 at 19:00










  • @jeevaa_v I did normalize the data. Previously, it was like > 10,000 so I took the logs of each datapoint
    – user3492226
    Nov 8 at 19:00










  • @user3492226, yes sorry, no doubt you were aware of that! If the loss wasn't NaN from the first epoch I'd suspect an exploding gradient, but it that seems less likely under the circumstances. Your data, as presented in the question, is of a notably different form to the Iris dataset. Can you share the code you've used to convert it to the Iris format?
    – Chris
    Nov 8 at 19:30


















  • When I run your code using the get_data function the programme works as expected. I suggest looking at what is returned by the get_MY_data and get_inputs_and_outputs functions for problems to start with.
    – Chris
    Nov 8 at 7:26










  • Did you try normalizing the feature values?
    – jeevaa_v
    Nov 8 at 8:13










  • @Chris I know, I am trying to use my own data instead of the iris dataset, and for some reason whenever I do that everything stops working.
    – user3492226
    Nov 8 at 19:00










  • @jeevaa_v I did normalize the data. Previously, it was like > 10,000 so I took the logs of each datapoint
    – user3492226
    Nov 8 at 19:00










  • @user3492226, yes sorry, no doubt you were aware of that! If the loss wasn't NaN from the first epoch I'd suspect an exploding gradient, but it that seems less likely under the circumstances. Your data, as presented in the question, is of a notably different form to the Iris dataset. Can you share the code you've used to convert it to the Iris format?
    – Chris
    Nov 8 at 19:30
















When I run your code using the get_data function the programme works as expected. I suggest looking at what is returned by the get_MY_data and get_inputs_and_outputs functions for problems to start with.
– Chris
Nov 8 at 7:26




When I run your code using the get_data function the programme works as expected. I suggest looking at what is returned by the get_MY_data and get_inputs_and_outputs functions for problems to start with.
– Chris
Nov 8 at 7:26












Did you try normalizing the feature values?
– jeevaa_v
Nov 8 at 8:13




Did you try normalizing the feature values?
– jeevaa_v
Nov 8 at 8:13












@Chris I know, I am trying to use my own data instead of the iris dataset, and for some reason whenever I do that everything stops working.
– user3492226
Nov 8 at 19:00




@Chris I know, I am trying to use my own data instead of the iris dataset, and for some reason whenever I do that everything stops working.
– user3492226
Nov 8 at 19:00












@jeevaa_v I did normalize the data. Previously, it was like > 10,000 so I took the logs of each datapoint
– user3492226
Nov 8 at 19:00




@jeevaa_v I did normalize the data. Previously, it was like > 10,000 so I took the logs of each datapoint
– user3492226
Nov 8 at 19:00












@user3492226, yes sorry, no doubt you were aware of that! If the loss wasn't NaN from the first epoch I'd suspect an exploding gradient, but it that seems less likely under the circumstances. Your data, as presented in the question, is of a notably different form to the Iris dataset. Can you share the code you've used to convert it to the Iris format?
– Chris
Nov 8 at 19:30




@user3492226, yes sorry, no doubt you were aware of that! If the loss wasn't NaN from the first epoch I'd suspect an exploding gradient, but it that seems less likely under the circumstances. Your data, as presented in the question, is of a notably different form to the Iris dataset. Can you share the code you've used to convert it to the Iris format?
– Chris
Nov 8 at 19:30












1 Answer
1






active

oldest

votes

















up vote
0
down vote













This is almost always a problem with the input data.



I would suggest inspecting in detail the values you are feeding into the model to make sure the model is receiving what you think it is.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53202563%2ftensorflow-nan-loss-and-constant-accuracy-when-training%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    This is almost always a problem with the input data.



    I would suggest inspecting in detail the values you are feeding into the model to make sure the model is receiving what you think it is.






    share|improve this answer

























      up vote
      0
      down vote













      This is almost always a problem with the input data.



      I would suggest inspecting in detail the values you are feeding into the model to make sure the model is receiving what you think it is.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        This is almost always a problem with the input data.



        I would suggest inspecting in detail the values you are feeding into the model to make sure the model is receiving what you think it is.






        share|improve this answer












        This is almost always a problem with the input data.



        I would suggest inspecting in detail the values you are feeding into the model to make sure the model is receiving what you think it is.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 10:40









        jfaucett

        47339




        47339






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53202563%2ftensorflow-nan-loss-and-constant-accuracy-when-training%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Verwaltungsgliederung Dänemarks

            Liste der Kulturdenkmale in Wilsdruff