Data Science Asked by Engr. double minded on May 29, 2021
I’m using Tensorflow 2 and using model.fit for training the model. but when I try to run it, it says Failed to convert a NumPy array to a Tensor (Unsupported object type float). Where I’m making mistake?enter image description here
import tensorflow as tf
print(tf.__version__)
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('datatraining.txt').values
type(data)
import numpy as np
data.shape
X = data[:,2:7]
Y = data[:,7]
X.shape
Y.shape
from sklearn.model_selection import train_test_split
# split the data into train and test sets
# this lets us simulate how our model will perform in the future
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.33)
N, D = X_train.shape
model = tf.keras.models.Sequential([
tf.keras.layers.Input(shape=(D,)),
tf.keras.layers.Dense(1, activation='sigmoid')
])
# Alternatively, you can do:
# model = tf.keras.models.Sequential()
# model.add(tf.keras.layers.Dense(1, input_shape=(D,), activation='sigmoid'))
model.compile(optimizer='adam',
loss='binary_crossentropy',
metrics=['accuracy'])
# Train the model
r = model.fit(X_train, y_train, validation_data=(X_test, y_test), epochs=100)
# Evaluate the model - evaluate() returns loss and accuracy
print("Train score:", model.evaluate(X_train, y_train))
print("Test score:", model.evaluate(X_test, y_test))
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP