0

I'm trying to run a neural network. And I have some questions related to this error, beacuase I'm trying to convert categorical inputs into numerical ordinary input.

So the data equals:

data base

so I used this code in order to be capable of handle those categorical input in the 'Test' and 'Measurement Stage' columns:

import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split, KFold
from sklearn.preprocessing import StandardScaler, LabelEncoder
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import Adam
from sklearn.metrics import r2_score

# Load your dataset
data = pd.read_excel('Teste JMP.xlsx')

# Separate the input features from the target outputs
X = data.drop(['Brookfield', 'Marsh'], axis=1).values
y = data[['Brookfield', 'Marsh']].values

# Apply label encoding to categorical columns
label_encoder = LabelEncoder()
X['Test'] = label_encoder.fit_transform(X['Test'])

Therefore, I obtained the error in the title. Can anyone help me?

I though the problem was the index type or the dataframe/numpy form, but when I switched the 'Marsh' for example for a number the error was this:

TypeError: Encoders require their input to be uniformly strings or numbers. Got ['float', 'int', 'str']

  • Please set the title to a clearer question, a summary, and not specific errors – Clau St Aug 29 '23 at 11:39
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 29 '23 at 11:40

1 Answers1

0

You could try out this new snippet, It should work. If not, just let me know !

import pandas as pd
from sklearn.model_selection import train_test_split, KFold
from sklearn.preprocessing import StandardScaler, LabelEncoder
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import Adam
from sklearn.metrics import r2_score

# Load your dataset
data = pd.read_excel('Teste JMP.xlsx')

# Separate the input features from the target outputs
X = data.drop(['Brookfield', 'Marsh'], axis=1).values
y = data[['Brookfield', 'Marsh']].values

# Convert 'Test' column to string type
X['Test'] = X['Test'].astype(str)

# Apply label encoding to categorical columns
label_encoder = LabelEncoder()
X['Test'] = label_encoder.fit_transform(X['Test'])```
  • Hi @TriveeCodez ! Thank you very much for your help! I tried, but it returned the same error :( – Leonor Magalhães Aug 29 '23 at 13:15
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 29 '23 at 19:18