# Multi Linear Regression Example
import tensorflow as tf

data = [[2,0,81],[4,4,93],[6,2,91],[8,3,97]]
x1 = [x_row[0] for x_row in data]
x2 = [x_row[1] for x_row in data]
y_data = [y_row[2] for y_row in data]

learning_rate = 0.1
a1 = tf.Variable(tf.random_uniform([1], 0, 10, dtype=tf.float64, seed=0))
a2 = tf.Variable(tf.random_uniform([1], 0, 10, dtype=tf.float64, seed=0))
b = tf.Variable(tf.random_uniform([1], 0, 100, dtype=tf.float64, seed=0))

y = a1*x1 + a2*x2 + b
rmse = tf.sqrt(tf.reduce_mean(tf.square(y - y_data)))
gradient_decent = tf.train.GradientDescentOptimizer(learning_rate).minimize(rmse)

with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())    
    for step in range(40001):        
        sess.run(gradient_decent)
        if step % 1000 == 0:
            print("Epoch_%4d -> RMSE=%.4f, 기울기1(a1)=%.4f, 기울기2(a2)=%.4f, 절편(b)=%.4f"
                  % (step, sess.run(rmse), sess.run(a1), sess.run(a2), sess.run(b)))

    test_x1 = [2,3,5,10]
    test_x2 = [3,4,1,5]
    test_y = a1*test_x1 + a2*test_x2 + b
    print(sess.run(test_y))
    

#Epoch_   0 -> RMSE=66.5350, 기울기1(a1)=1.7125, 기울기2(a2)=1.4369, 절편(b)=12.1789
#Epoch_1000 -> RMSE=10.1057, 기울기1(a1)=5.1511, 기울기2(a2)=3.5464, 절편(b)=52.7885
#Epoch_2000 -> RMSE=1.8370, 기울기1(a1)=1.7783, 기울기2(a2)=2.4111, 절편(b)=77.8445
#Epoch_3000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_4000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_5000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_6000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_7000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_8000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_9000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_10000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_11000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_12000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_13000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_14000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_15000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_16000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_17000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_18000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_19000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_20000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_21000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_22000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_23000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_24000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_25000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_26000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_27000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_28000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_29000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_30000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_31000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_32000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_33000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_34000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_35000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_36000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_37000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_38000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_39000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#Epoch_40000 -> RMSE=1.8370, 기울기1(a1)=1.7699, 기울기2(a2)=2.4082, 절편(b)=77.9026
#[ 88.6668933   92.84495408  89.16026712 107.64240934]
