Home>

Now, in Python keras, I am trying to do deep learning using two CSV data (14 columns, 100 rows).

I don't understand the meaning of the error.

Error message
InvalidArgumentError (see above for traceback): Received a label value of 1902 which is outside the valid range of [0, 8). Label values: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1573 0 0 0 0 0 0 0 0 0 0 0 1408 0 0 0 1902 0 0 0 0 0 0 0
     [[Node: loss/dense_4_loss/SparseSoftmaxCrossEntropyWithLogits/SparseSoftmaxCrossEntropyWithLogits = SparseSoftmaxCrossEntropyWithLogits [T = DT_FLOAT, Tlabels = DT_INT64, _device = "/ job: localhost/replica: 0/task: 0/device: CPU: 0"] Reshape_1, loss/dense_4_loss/Cast)]]
Corresponding source code
import pandas as pd
import numpy as np

from keras.datasets import mnist
from keras.models import Sequential, model_from_json
from keras.layers.core import Dense, Dropout
from keras.utils import np_utils


#Specify label
train = pd.read_csv ("data_train.csv", encoding = "utf-8"
                    , sep = ",", header = None)
X_train = train [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13]]
y_train = train [11]

test = pd.read_csv ("data_test.csv", encoding = "utf-8"
                   , sep = ",", header = None)
X_test = test [[0, 1, 2, 3, 4, 5, 7, 6, 8, 9, 10, 12, 13]]
y_test = test [11]


# one-hot
X_train = pd.get_dummies (X_train, columns = [1, 3, 5, 6, 7, 8, 9, 13])

X_test = pd.get_dummies (X_test, columns = [1, 3, 5, 6, 7, 8, 9, 13])





model = Sequential ([Dense (40, activation = "relu", input_dim = 67), Dropout (0.2),
                    Dense (20, activation = "relu"), Dropout (0.2),
                    Dense (10, activation = "relu"), Dropout (0.2),
                    Dense (8, activation = "softmax")])


model.compile (optimizer = "adam", loss = "sparse_categorical_crossentropy"
              , metrics = ["accuracy"])



hist = model.fit (X_train, y_train, batch_size = 47, epochs = 100, verbose = 2)


model.summary ()
comment

Isn't the PC specs insufficient?

  • Answer # 1

    The error message is

    "InvalidArgumentError (see above for traceback): Received a label value of 1902 which is outside the valid range of [0, 8). Label values: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1573 0 0 0 0 0 0 0 0 0 0 0 1408 0 0 0 1902 0 0 0 0 0 0 0 "
    [Literally] "Invalid argument" error (see above for trace history): The received label value 1902 is outside the valid range [0, 8).
    Label value: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1573 0 0 0 0 0 0 0 0 0 0 0 1408 0 0 0 1902 0 0 0 0 0 0 0

    Therefore, it is not an error caused by the specifications of the PC.

    Find the code in the error trace history that sets the label value to a number (1573,1408,1902) that deviates from the valid interval [0,8) (0 or more, less than 8), and so on. Please identify the part that caused the setting.
    Then, correct it so that the normal label value (within the range of 0 or more and less than 8) is set.