Click here to Skip to main content
15,909,030 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Traceback (most recent call last):
  File "C:/Users/USER/PycharmProjects/KKOP/neuralN.py", line 10, in <module>
    X = data[:284,0:43]
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\frame.py", line 2899, in __getitem__
    indexer = self.columns.get_loc(key)
  File "C:\Users\USER\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\indexes\base.py", line 2889, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas\_libs\index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 75, in pandas._libs.index.IndexEngine.get_loc
TypeError: '(slice(None, 284, None), slice(0, 43, None))' is an invalid key


What I have tried:

<pre><pre lang="Python">

import pandas as pd

data = pd.read_csv('bin_data.csv',sep=';')
print(data)
X = data[:284,0:43]
print(X)
Y = data[:284,43]

model = Sequential()

model.add(Dense(20, input_dim=9, init='uniform', activation='relu'))
model.add(Dense(12, init='uniform', activation='relu'))
model.add(Dense(9, init='uniform', activation='sigmoid'))
model.add(Dense(1, init='uniform', activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

model.fit(X, Y, nb_epoch=150, batch_size=10,  verbose=2)
scores = model.evaluate(X,Y)
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))
Posted
Updated 1-Sep-22 9:43am

1 solution

Error seems to be with:
X = data[:284,0:43]


You have a dataframe and you want to split it into X & Y for features and output.

Try with iloc or loc here. (Wha you are trying would work with numpy)
X = data.iloc[:284,0:43]
Y = data.iloc[:284,43]

Refer: How do I select a subset of a DataFrame? — pandas 1.1.1 documentation[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900