Tensorflow CSV Data

Asked

Viewed 60 times

0

Personal I would like to assemble my training_x and training_y from the CSV someone knows how to proceed, I started but could not finish.

import tensorflow as tf 
from tensorflow import keras
import os
import pandas


model = keras.Sequential()

input_layer = keras.layers.Dense(3, input_shape=[3], activation='tanh')
model.add(input_layer)
output_layer = keras.layers.Dense(1, activation='sigmoid')
model.add(output_layer)
gd = tf.train.GradientDescentOptimizer(0.01)
model.compile(optimizer=gd, loss='mse')

dir_path = os.path.dirname(os.path.realpath(__file__))
filename = dir_path + "dados.csv"

......

training_x = tf.Variable([[1, 1, 0], [1, 1, 1], [0, 1, 0], [-1, 1, 0], [-1, 0, 0], [-1, 0, 1],[0, 0, 1], [1, 1, 0], [1, 0, 0], [-1, 0, 0], [1, 0, 1], [0, 1, 1], [0, 0, 0], [-1, 1, 1]])

training_y = tf.Variable([[0], [0], [1], [1], [1], [0], [1],[0], [1], [1], [1], [1], [1], [0]])

My CSV

outlook,Humidity,Wind,play

1,1,0,0

1 answer

0


Follows the resolution:

file = ("dados.csv")

def data_encode(file):
    X = []
    Y = []
    train_file = open(file, 'r')
    for line in train_file.read().strip().split('\n'):
        line = line.split(',')
        X.append([int(line[0]), int(line[1]), int(line[2])])
        Y.append(int(line[3]))
    return X, Y

train_X , train_Y = data_encode(file)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.