I am trying to fit my model (neural networks) using keras but I got ValueError error.
import keras
from keras.models import Sequential
from keras.layers import Dense
classificador_rede_neural = Sequential()
# # Camadas Ocultas e de Saída
# camadas ocultas = (entradas + saídas)/2 #estimando o numero de neurônios em camada oculta
#
# temos:len(train.columns) - 1 atributos previsores
#
# 1 classe
#len(train.columns)
camadas_ocultas = round(len(train.columns)/2)
print(camadas_ocultas)
classificador_rede_neural.add(Dense(units=camadas_ocultas, activation='relu',input_dim =len(train.columns) ))#primeira camada
classificador_rede_neural.add(Dense(units=camadas_ocultas, activation='relu' ))#segunda camada
classificador_rede_neural.add(Dense(units=1, activation='sigmoid' ))#camada de saída. a saída é binária, logo units=1
classificador_rede_neural.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
classificador_rede_neural.fit(X_train2,y_train2,batch_size=10,epochs =100)
I am getting the error:
ValueError: Please provide as model inputs either a single array or a list of arrays. You passed: x= sload dload spkts dpkts swin dwin smean dmean \
0 1.803636e+08 0.000000 2 0 0 0 248 0
1 8.810000e+08 0.000000 2 0 0 0 881 0
2 8.544000e+08 0.000000 2 0 0 0 534 0
3 6.000000e+08 0.000000 2 0 0 0 450 0
4 8.504000e+08 0.000000 2 0 0 0 1063 0
5 1.045333e+09 0.000000 2 0 0 0 392 0
6 1.306667e+09 0.000000 2 0 0 0 980 0
7 1.977143e+08 0.000000 2 0 0 0 692 0
[82332 rows x 22 columns]
How could I fit the model? What is wrong with my data?
The complete code > https://pastebin.com/jE7erEJs
I think the problem is that you passed to your model an entire pandas dataset together with the columns headers and an index column. In order to train your model on your data, convert it to a numpy array first with X_train2.values
and y_train2.values
since a Keras model accepts as input a numpy array and not a pandas dataset
Similar question
Pandas DataFrame and Keras
Documentation on Keras' Sequential model
https://keras.io/models/sequential/
Edit to answer the comments
Don't convert each column separately, this is pointless. Assuming that you have a general dataset df
with a column called labels
what you have to do is
labels = df.pop("labels")
model.fit(x=df.values, y=labels.values)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With