我使用Keras,RNN训练KDD CUP数据集。
当我训练时,我有这个错误。
"ValueError: ('Bad input argument to theano function with name
"/usr/local/lib/python2.7/dist-packages/Keras-1.0.5-py2.7.egg/keras/backend/theano_backend.py:527"
at index 0 (0-based)', "invalid literal for long() with base 10: 'SF'")"
这是我的代码:
from __future__ import print_function
import numpy as np
np.random.seed(1337) # for reproducibility
import keras
from keras.preprocessing import sequence
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Embedding
from keras.layers import LSTM, SimpleRNN, GRU
import pandas as pd
max_features = 5000000
maxlen = 50 # cut texts after this number of words (among top max_features most common words)
batch_size = 32
nb_epoch = 100
print('Loading data...')
train_data=pd.read_csv('./data.csv')
labels = (train_data.ix[:,41:42].values)
train = (train_data.ix[:,0:41].values)
#labels = np_utils.to_categorical(labels)
test_data=pd.read_csv('./testdata.csv')
test = (test_data.ix[:,0:41].values)
'''
print('labels')
print(labels)
print('train')
print(train)
print('test')
print(test)
'''
print(train_data.shape[1])
print(train.shape)
print(labels.shape)
print('Build model...')
model = Sequential()
model.add(Embedding(max_features, 128, dropout=0.2))
model.add(LSTM(128, dropout_W=0.2, dropout_U=0.2)) # try using a GRU instead, for fun
model.add(Dense(1))
model.add(Activation('sigmoid'))
# try using different optimizers and different optimizer configs
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
print('Train...')
model.fit(train, labels, batch_size=batch_size, nb_epoch=nb_epoch, validation_split=0.25, verbose=1, shuffle=True)
store = model.predict(test, verbose=0)
print('Test score:', score[0])
print('Test accuracy:', score[1])