-1
Hello. I’m creating a neural network to categorize some data. Basically the neural network will tell me which molecule is.
This is my code:
import pandas as pd
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers import Dense, Dropout
from sklearn.model_selection import cross_val_score
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.preprocessing import LabelEncoder, StandardScaler
#%%
base = pd.read_csv('fotoacustica-mol.csv')
atributos = base.iloc[:, :-1].to_numpy('float64')
classe = base.iloc[:, -1].to_numpy()
scaler = StandardScaler()
atributos = scaler.fit_transform(atributos)
encoder = LabelEncoder()
classe = encoder.fit_transform(classe)
classe = np_utils.to_categorical(classe)
#%%
def neuralNetwork():
classificador = Sequential()
classificador.add(Dense(units=4, activation='relu', input_dim=4))
classificador.add(Dropout(0.2))
classificador.add(Dense(units=4, activation='relu'))
classificador.add(Dropout(0.2))
classificador.add(Dense(units=3, activation='softmax'))
classificador.compile(optimizer='adam', loss='categorical_crossentropy',
metrics=['categorical_accuracy'])
return classificador
#%%
classificador = KerasClassifier(build_fn=neuralNetwork, epochs=10,
batch_size=10)
resultados = cross_val_score(estimator=classificador,
X=atributos, y=classe,
cv=10, scoring='accuracy')
However this error occurs when you run the other portion of the database
ValueError: Classification metrics can't handle a mix of multilabel-indicator and binary targets
I don’t understand what it is. I thank you in advance.
My attribute class has Shape (806, 4) while my class has (806, 3). I checked all this anyway the error persists.
– juniorcl
I managed to run doing only categorical (0, 1, 2), but it is not yet as I want to implement.
– juniorcl
The problem is not related to the attributes but to the class. You have two options, out works with Y.Shape=(806, 1) and assigning values [0] or [1] or [2] or with Y.Shape=(806, 3) and [1, 0, 0] or [0, 1, 0] or [0, 0, 1] (whereas you are not working with multi label)
– rriccilopes