Reputation: 13
I hope I am doing this right (first post).
I tried to use tensorflow.keras to classify the data from here. I am aware the input shape, shape of input data and shape of targets are important when passing arguments into tf.keras.Sequential.fit()
The message I get is:
ValueError: Error when checking input: expected dense_159_input to have 2 dimensions, but got array with shape ()
So here is what I have done:
def loadDataset(file_name):
data = pd.read_csv("data/" + file_name)
# print(data.head(10))
data = data.to_numpy()
random.seed(20)
X = data[:, 0:8]
y = data[:, -1]
X = np.asarray(X).reshape(X.shape[0], X.shape[1])
X = tf.keras.utils.normalize(X, axis=0)
y = np.asarray(y).reshape(y.shape[0], 1)
return X, y
title = "datasets_228_482_diabetes.csv"
X, y = loadDataset(title)
print(X.shape)
print(y.shape)
(768, 8) (768, 1)
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, Flatten
from tensorflow.keras.optimizers import Adam
model = Sequential()
model.add(Dense(4, activation = "relu", input_shape=(8,)))
model.add(Dense(4, activation = "relu"))
model.add(Dense(1, activation = "sigmoid"))
model.compile(optimizer = "Adam",
loss = "binary_crossentropy",
metrics=["accuracy"])
model.fit(X, y, batch_size = 16, epochs = 1, validation_data = 0.1)
I tried making the shapes X (768, 8, 1) and y (768, 1, 1) instead in case that was the issue but then the error says it expected 2 dimensions but got three. Which makes total sense to me. I just don't understand the error above saying that the input data X has no shape when X is of shape (768, 8).
Any help would be greatly appreciated! Cheers
Upvotes: 1
Views: 100
Reputation: 1290
I would say that the error comes from validation_data
which is supposed to be as X
, some data shaped (..., 8)
. Since you are passing 0.1
the dense layer doesn't understand what you are giving him.
Upvotes: 3