Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

showing raise KeyError('%s not in index' % objarr[mask]) #2262

Closed
vinayakumarr opened this issue Apr 11, 2016 · 3 comments
Closed

showing raise KeyError('%s not in index' % objarr[mask]) #2262

vinayakumarr opened this issue Apr 11, 2016 · 3 comments

Comments

@vinayakumarr
Copy link

have dataset with 41 features and one output which has 23 class
i modified the imdb sentimental classification example lstm for my dataset and it is showing error. please have a look on the attached image.

I am trying to implement

  1. two memory blocks and two cells each
  2. four memory blocks and two cells each
  3. two memory blocks and four cells each
  4. eight memory blocks and four cells each

from future import print_function
import numpy as np
np.random.seed(1337)

from keras.preprocessing import sequence
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.layers.embeddings import Embedding
from keras.layers.recurrent import LSTM

from sklearn.cross_validation import train_test_split
import pandas as pd

max_features = 494021
maxlen = 100 # cut texts after this number of words (among top max_features most common words)
batch_size = 32

print('Loading data...')
data = pd.read_csv('kddtrain.csv', header=None)

X = data.iloc[:,1:42]
y = data.iloc[:,0]

X_train, X_test, y_train, y_test = train_test_split(X, y,test_size=0.2,random_state=42)

print(len(X_train), 'train sequences')
print(len(X_test), 'test sequences')
print(X_train.shape)

print('Pad sequences (samples x time)')

X_train = sequence.pad_sequences(X_train, maxlen=maxlen)

X_test = sequence.pad_sequences(X_test, maxlen=maxlen)

print('X_train shape:', X_train.shape)

print('X_test shape:', X_test.shape)

print('Build model...')
model = Sequential()
model.add(Embedding(max_features, 128, input_length=maxlen, dropout=0.5))
model.add(LSTM(128, dropout_W=0.5, dropout_U=0.1)) # try using a GRU instead, for fun
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam')

print('Train...')
model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=15,
validation_data=(X_test, y_test), show_accuracy=True)
score, acc = model.evaluate(X_test, y_test,
batch_size=batch_size,
show_accuracy=True)
print('Test score:', score)
print('Test accuracy:', acc)

untitled

@vedu4489
Copy link

Hi @vinayakumarr Did you find out what was causing the error?

@edumucelli
Copy link
Contributor

@vinayakumarr @vedu4489 you should convert your X_train and y_train in a numpy array. E.g.,:

import numpy as np
...
model.fit(np.array(X_train), np.array(y_train), ... 

@stale stale bot added the stale label Sep 26, 2017
@stale
Copy link

stale bot commented Sep 26, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.

@stale stale bot closed this as completed Oct 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants