import pandas as pd
data=pd.read_csv("tesdata.csv")
data
x=data.iloc[:,0:2].values
y=data.iloc[:,2].values
from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
x=sc.fit_transform(x)
y=sc.fit_transform(y.reshape(1,-1))
from keras.models import Sequential
from keras.layers import Dense

model=Sequential()
model.add(Dense(2, activation='relu'))
model.add(Dense(10, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='mean_squared_error',optimizer='Adam',metrics=['accuracy'])
model.fit(x,y.reshape(1,-1),epochs=30,batch_size=21)

ValueError: Data cardinality is ambiguous:

x sizes: 21 y sizes: 1

Please provide data which shares the same first dimension.

my data

1

There are 1 best solutions below

0
AudioBubble On

I have replicated the same issue with one of sample csv file.

I found that you need not to standardize or reshape the label here. Check below code snippets:

x=data.iloc[:,0:7].values
y=data.iloc[:,7].values

from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
x=sc.fit_transform(x)

#y=sc.fit_transform(y.reshape(1,-1))  # Need not to standardize the label

from keras.models import Sequential
from keras.layers import Dense

model=Sequential()
model.add(Dense(2, activation='relu'))
model.add(Dense(10, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='mean_squared_error',optimizer='Adam',metrics=['accuracy'])
model.fit(x,y,epochs=10,batch_size=21)   #put y instead of y.reshape(1,-1)

Output:

Epoch 1/10
159/159 [==============================] - 4s 8ms/step - loss: 97.8257 - accuracy: 3.0120e-04
Epoch 2/10
159/159 [==============================] - 1s 9ms/step - loss: 94.2889 - accuracy: 3.0120e-04
Epoch 3/10
159/159 [==============================] - 1s 8ms/step - loss: 90.9619 - accuracy: 3.0120e-04
Epoch 4/10
159/159 [==============================] - 1s 8ms/step - loss: 89.7787 - accuracy: 3.0120e-04
Epoch 5/10
159/159 [==============================] - 1s 8ms/step - loss: 89.5762 - accuracy: 3.0120e-04
Epoch 6/10
159/159 [==============================] - 1s 7ms/step - loss: 89.5045 - accuracy: 3.0120e-04
Epoch 7/10
159/159 [==============================] - 1s 8ms/step - loss: 89.4718 - accuracy: 3.0120e-04
Epoch 8/10
159/159 [==============================] - 1s 7ms/step - loss: 89.4559 - accuracy: 3.0120e-04
Epoch 9/10
159/159 [==============================] - 1s 7ms/step - loss: 89.4472 - accuracy: 3.0120e-04
Epoch 10/10
159/159 [==============================] - 1s 9ms/step - loss: 89.4420 - accuracy: 3.0120e-04
<keras.callbacks.History at 0x7f59f0b1c7d0>