머신러닝

x**(1/3)=0 TensorFlow 수치해 파이선 코드

coding art 2018. 11. 25. 16:46
728x90

# x_1_3_eqn_regression_01.py

import tensorflow as tf

x_train = [1.0, 2.0]
y_train = [1.0, 1.2599]

W1 = tf.Variable(tf.random_uniform([1],0.5, 1.0, dtype = tf.float32, name='weight'))

hypothesis = (x_train - W1)**(1./3.)

cost = tf.reduce_mean(tf.square(hypothesis - y_train))

optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.05)
train = optimizer.minimize(cost)

sess = tf.Session()
sess.run(tf.global_variables_initializer())


for step in range(2001):
    sess.run(train)
    if step % 500 == 0:
        print(step, sess.run(cost), sess.run(W1))