Skip to main content
8 de 9
se añadieron 318 caracteres en el cuerpo; título editado

Problema> Tensorflow - ValueError: Failed to convert a NumPy array to a Tensor

Esty haciendo una red neuronal pero obtengo un error en los datos que no me permite ejecutar el scrip. Mis datos son un conjunto de 9568 filas y 5 columnas. En formato csv delimitados por comas. introducir la descripción de la imagen aquí

Este es parte del codigo que uso:

from keras.models import Sequential
from keras.layers import Dense
import numpy
import pandas
import matplotlib.pyplot as plt
import scipy.stats

seed = 7
numpy.random.seed(seed)

from google.colab import auth
auth.authenticate_user()
from pydrive.drive import GoogleDrive
from pydrive.auth import GoogleAuth
from oauth2client.client import GoogleCredentials
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
myfile = drive.CreateFile({'id': '1uJ0Y_WF1OspE46fAulNJPokdZ9gbfQYl'})
myfile.GetContentFile('EstudioCaso.csv')


dataset = numpy.genfromtxt("EstudioCaso.csv", skip_header=1, dtype="f,f,f,f,f", unpack=True, delimiter=",,")
print (dataset)
training_data = numpy.genfromtxt("EstudioCaso.csv", skip_header=1, usecols=(0, 1, 2, 4), dtype="f,f,f,f,f", unpack=True, delimiter=",,")
training_targets = numpy.genfromtxt("EstudioCaso.csv", skip_header=1, usecols=(4), dtype="f,f,f,f,f", unpack=True, delimiter=",,")

model = Sequential()
model.add(Dense(12, input_dim=5, kernel_initializer='uniform', activation='relu'))
model.add(Dense(5, kernel_initializer='uniform', activation='relu'))
model.add(Dense(1, kernel_initializer='uniform', activation='sigmoid'))

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(training_data, training_targets, epochs=200, batch_size=500)
scores = model.evaluate(training_data, training_targets)
print("%s: %.2f%%" % (model.metrics_names[1], scores[1] * 100))

Los datos son de la siguiente forma: [( 8.34, 40.77, 1010.84, 90.01, 480.48) (23.64, 58.49, 1011.4 , 74.2 , 445.75) (29.74, 56.9 , 1007.15, 41.91, 438.76) ... (15.99, 43.34, 1014.2 , 78.66, 465.96) (17.65, 59.87, 1018.58, 94.65, 450.93) (23.68, 51.3 , 1011.86, 71.24, 451.67)]

Y el error que obtengo es: Failed to convert a NumPy array to a Tensor (Unsupported numpy data type).