import tensorflow as tf

x_data = [11,12,13,14,15,16,17]
x_data_2 = [0, 0, 0, 0, 1, 1, 1]
y_data = [35, 44, 56, 72, 192, 200, 208]
w = tf.Variable(tf.random.normal([1]))
w_2 = tf.Variable(tf.random.normal([1]))
b = tf.Variable(tf.random.normal([1]))
learning_rate = 0.001
for i in range(20001):
    with tf.GradientTape() as tape:
        hypothesis = w * x_data + w_2 * x_data_2 + b
        cost = tf.reduce_mean(tf.square(hypothesis - y_data))
    w_grad, w_2_grad, b_grad = tape.gradient(cost, [w, w_2, b])
    w.assign_sub(learning_rate * w_grad)
    w_2.assign_sub(learning_rate * w_2_grad)
    b.assign_sub(learning_rate * b_grad)
    
    if i % 500 == 0:
      print(f'Step : {i}, Cost : {int(cost)}, Weight : {w.numpy()[0], w_2.numpy()[0]}, Bias : {b.numpy()[0]}')

temp_x = 18
temp_x_2 = 1
print()
print(f"온도가 {temp_x}도이며 프로모션 진행여부 {temp_x_2} 일 때, 에어컨 판매 예상 갯수 :", int(w * temp_x + w_2 * temp_x_2 + b))
반응형

+ Recent posts