2017-10-22 4 views
0

tensorflow 라이브러리를 사용하여 데이터 세트를 효율적으로 처리 할 수 ​​있습니까?tensorflow를 사용하여 데이터 집합의 형식을 변경하는 방법은 무엇입니까?

+0

지금까지 해보신 것은 무엇입니까? – Wndrr

+0

숫자 배열을 의미합니까? 팬더를 사용하는 것이 잘못된 이유는 무엇입니까? – Maxim

+0

사실 나는 완전히 초보자이며 파이썬에서 데이터 세트를 읽는 법을 알고 있었고 tensorflow를 통해 빠르고 효율적인 방법이 있는지 물어 보았습니다. 그러나 판다를 확인해 보면 @Maxim이 언급 한대로 내 작업을 수행해야합니다. – Adiaforos

답변

0

이 샘플 코드는 CSV 가져 오기, 일부 기본 조작 및 tensorflow에서 NN 학습을 시작하는 데 도움이됩니다. data here을 얻을 수 있습니다.

import numpy as np 
import pandas as pd 
import tensorflow as tf 

# Read and manipulate data from CSV 
df = pd.read_csv('df.csv') 
df = df.dropna(how='any') 
df = df.drop('DayOfWeek', axis=1) 
df.Customers = df.Customers/1000.0 
df.CompetitionDistance = df.CompetitionDistance/1000.0 
df.Sales = df.Sales/1000.0 

# Parameters 
features = 2 
hidden = 3 
learning_rate = 0.2 

# Prepare input and output arrays 
train_x = np.array(df[['CompetitionDistance', 'Customers']]) 
train_y = np.array(df[['Sales']]).reshape([-1]) 

# Build a simple TF graph 
x = tf.placeholder(tf.float32, shape=[None, features], name='x') 
y = tf.placeholder(tf.float32, shape=[None], name='y') 
W = tf.get_variable(name='W', shape=[features, hidden]) 
b = tf.get_variable(name='b', shape=[hidden], initializer=tf.zeros_initializer) 
z = tf.matmul(x, W) + b 
predict = tf.reduce_sum(z, axis=1) 
loss = tf.reduce_mean(tf.square(y - predict)) 
optimizer = tf.train.AdamOptimizer(learning_rate).minimize(loss) 

# Run the training 
with tf.Session() as session: 
    session.run(tf.global_variables_initializer()) 
    for i in xrange(101): 
    _, loss_value = session.run([optimizer, loss], 
           feed_dict={x: train_x, y: train_y}) 
    if i % 10 == 0: 
     print "epoch=%03i, loss=%.5f" % (i, loss_value)