How to *actually* read CSV data in TensorFlow?

前端 未结 5 1200
感动是毒
感动是毒 2020-11-28 22:32

I\'m relatively new to the world of TensorFlow, and pretty perplexed by how you\'d actually read CSV data into a usable example/label tensors in Te

5条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 23:14

    Or you could try this, the code loads the Iris dataset into tensorflow using pandas and numpy and a simple one neuron output is printed in the session. Hope it helps for a basic understanding.... [ I havent added the way of one hot decoding labels].

    import tensorflow as tf 
    import numpy
    import pandas as pd
    df=pd.read_csv('/home/nagarjun/Desktop/Iris.csv',usecols = [0,1,2,3,4],skiprows = [0],header=None)
    d = df.values
    l = pd.read_csv('/home/nagarjun/Desktop/Iris.csv',usecols = [5] ,header=None)
    labels = l.values
    data = numpy.float32(d)
    labels = numpy.array(l,'str')
    #print data, labels
    
    #tensorflow
    x = tf.placeholder(tf.float32,shape=(150,5))
    x = data
    w = tf.random_normal([100,150],mean=0.0, stddev=1.0, dtype=tf.float32)
    y = tf.nn.softmax(tf.matmul(w,x))
    
    with tf.Session() as sess:
        print sess.run(y)
    

提交回复
热议问题