0

i want to use a pandas dataset as an input to a neural net.

my neural net model is:

def build_model():
    model = Sequential()
    model.add(Dense(128, activation = "relu"))
    model.add(Dropout(0.2))
    model.add(Dense(64, activation = "relu"))
    model.add(Dropout(0.1))
    model.add(Dense(32, activation = "softmax"))

    model.compile(
        optimizer='adam',
        loss=['binary_crossentropy'],
        metrics=['accuracy']
    )
    return model

tensorboard = TensorBoard(log_dir=f"logs/{time.time()}", histogram_freq=1)

model = build_model()

history = model.fit(
    x_train,
    y_train,
    epochs=5,
    batch_size=32,
    validation_data=(
        x_val,
        y_val
    ),
    callbacks=[
        tensorboard
    ]
)

and i pass my dataframe as input as such:

y_val, x_val, y_train, x_train = test_data.drop(['gender', 
       'comorbidities_count', 'comorbidities_significant_count',
       'medication_count'],axis=1),test_data.drop(['fried'],axis=1),training_data.drop([ 'gender', 'comorbidities_count', 'comorbidities_significant_count',
       'medication_count'],axis=1),training_data.drop(['fried'],axis=1)

but i get this error:

ValueError: Please provide as model inputs either a single array or a list of arrays.

Does anyone know hot to turn this dataframe into an array so i can feed it? Or is there some other issue i am not in knowledge of?

1 Answer 1

1

Use

y_val, x_val, y_train, x_train = test_data.drop(['gender', 
       'comorbidities_count', 'comorbidities_significant_count',
       'medication_count'],axis=1).to_numpy().astype(np.float32) ,test_data.drop(['fried'],axis=1).to_numpy().astype(np.float32) ,training_data.drop([ 'gender', 'comorbidities_count', 'comorbidities_significant_count',
       'medication_count'],axis=1).to_numpy().astype(np.float32) ,training_data.drop(['fried'],axis=1).to_numpy().astype(np.float32) 

The .to_numpy() function of a pd dataframe turns it into a numpy array.

Sign up to request clarification or add additional context in comments.

13 Comments

now i get this: ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type int).
add .astype(np.float32) after every array. this will convert the arrays to float arrays
sorry but now i get: NotFoundError: Failed to create a directory: logs/1577540868.3478014\train; No such file or directory [Op:CreateSummaryFileWriter]
this is caused by the tensorboard = TensorBoard(log_dir=f"logs/{time.time()}", histogram_freq=1) line and not related to this issue
try to use log_dir="logs/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S") as your log dir. For that you have to import datetime.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.