Problems with neural network input data with scikit Learn

Asked

Viewed 139 times

1

I would like to create a neural network that returns 1 (one) to a specific case and 0 (zero) to all others.

The idea would be:

import numpy as np
import pandas as pd
from sklearn.preprocessing import MaxAbsScaler
from sklearn.neural_network import MLPClassifier

# transforma o dado (3000 valores) em um dataframe

traco = pd.read_fwf('2_traco48.txt', header=None)

# recorta o dado em janelas com 100 valores

for i in range(0,2901):
    janela[i] = traco[i:i+100]
    print janela[i]

# lista com todas as janelas

janelas [janela0, janela1, janela2, ... janela 2900, janela2901]

# saida desejada (caso hipotetico, a ultima saida sera 1 e as outras seriam 0)

saida = [0, 0, 0, 0, 0, ... 0, 0, 0, 1]

# treinando

ann =  MLPClassifier(solver='lbfgs', hidden_layer_sizes=(10, 10), activation='logistic', alpha=1e-5,)
print(ann.fit(janelas, saida))

I have not yet made the "crop" parts of the windows or specify the list with the position of 1 and the zeroes, and normalize the data to be between 1 and -1.

Testing a simpler example, with only 4 "windows" with 100 input values each window, to see how it would be running, I came across a problem:

data0 = pd.read_fwf('data0.txt', index=False)
data1 = pd.read_fwf('data1.txt', index=False)
data2 = pd.read_fwf('data2.txt', index=False)
data3 = pd.read_fwf('data3.txt', index=False)

dado_treino = [data0, data1, data2, data3]
treino_superv = [0, 0, 0, 1]

print(ann.fit(dado_treino, treino_superv))

I turned the files 'data[i]. txt' from 2D to 1D, but it’s not working...

ValueError: cannot copy sequence with size 99 to array axis with dimension 1

I believe the error is in converting the data from 2D to 1D with pandas, but it may be something on the network, or something conceptually wrong.

  • 1

    Can you post the full msg error? With the exact line where it’s happening it’s easier to know what the problem is :)

  • Victor Capone, the error is "Valueerror: cannot copy Sequence with size 99 to array Axis with Dimension 1". The point is that my data should be an array of a line, which I’m not able to do.

  • It would be interesting if you post error message. But from what I understand you are using 4 pandas.Dataframes within an array. Type you should look at each of these DF and see without has the same size. as ta Shape. type problem is in preprocessing .

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.