ValueError:在keras训练时无法将字符串转换为float

时间:2017-05-11 19:34:12

标签: neural-network keras

我正在尝试使用keras运行基本的神经网络:

import numpy
    import pandas
    from keras.models import *
    from keras.layers import *
    from keras.optimizers import *

    dataframe = pandas.read_csv("data/mydata.csv", header=None) 
    dataset = dataframe.values
    # split into input (X) and output (Y) variables
    X = dataset[:,0:21] #X features 
    Y = dataset[:,21] # Y labels

#Define Neural network model of 10 Hidden layer with 500 Neurons each
model = Sequential()
model.add(Dense(500, input_dim=21, init='normal', activation='relu')) #Input Layer 
model.add(Dense(500, init='normal', activation='relu')) #Hidden Layer 1
model.add(Dense(500, init='normal', activation='relu')) #Hidden layer 2
model.add(Dense(500, init='normal', activation='relu')) #Hidden Layer 3
model.add(Dense(500, init='normal', activation='relu')) #Hidden Layer 4
model.add(Dense(500, init='normal', activation='relu')) #Hidden Layer 5
model.add(Dense(500, init='normal', activation='relu')) #Hidden Layer 6
model.add(Dense(500, init='normal', activation='relu')) #Hidden Layer 7
model.add(Dense(500, init='normal', activation='relu')) #Hidden Layer 8
model.add(Dense(500, init='normal', activation='relu')) #Hidden Layer 9
model.add(Dense(500, init='normal', activation='relu')) #Hidden Layer 10
model.add(Dense(1, init='normal', activation='sigmoid')) #Output later
print('Modeled Network')

# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'] ) 
 #fits the data point X, Y to the model
model.fit(X, Y, validation_split=0.3, shuffle=True, nb_epoch=50, batch_size=5000)

# serialize model to JSON
print("* Saving model to disk..")
model_json = model.to_json()
with open("models/model.json", "w") as json_file:
  json_file.write(model_json)
# serialize weights to HDF5
model.save_weights("models/model.h5")

但是,我收到了错误:

编译期间

ValueError: could not convert string to float: 'feature21'。我对此很新,所以我不确定为什么它会尝试将字符串转换为浮点数,因为数据集中的标题已关闭,而且该功能本身完全是数字。是否已经有一个已知的简单解决方案?

0 个答案:

没有答案