<jupyter_start><jupyter_text>Lab 4 Multi-variable linear regression  Lab04-1-multi_variable_linear_regression<jupyter_code>import tensorflow as tf
tf.set_random_seed(777)  # seed 지정
# 독립변수 3개, 종속변수 1개
x1_data = [73., 93., 89., 96., 73.]
x2_data = [80., 88., 91., 98., 66.]
x3_data = [75., 93., 90., 100., 70.]

y_data = [152., 185., 180., 196., 142.]
# placeholder 변수 생성
x1 = tf.placeholder(tf.float32)
x2 = tf.placeholder(tf.float32)
x3 = tf.placeholder(tf.float32)

Y = tf.placeholder(tf.float32)
# weight, bias initial value 지정
w1 = tf.Variable(tf.random_normal([1]), name='weight1')
w2 = tf.Variable(tf.random_normal([1]), name='weight2')
w3 = tf.Variable(tf.random_normal([1]), name='weight3')
b = tf.Variable(tf.random_normal([1]), name='bias')
# regression model(y_hat)
hypothesis = x1 * w1 + x2 * w2 + x3 * w3 + b
print(hypothesis) # 출력결과 : Tensor("add_2:0", dtype=float32)
# cost/loss function (MSE)
cost = tf.reduce_mean(tf.square(hypothesis - Y))
# Optimization(Minimize) => 아주 작은 learning rate 사용!!
optimizer = tf.train.GradientDescentOptimizer(learning_rate=1e-5)   # 1e-5 : 0.00001
train = optimizer.minimize(cost)
# Session 생성 및 변수 초기화
sess = tf.Session()
sess.run(tf.global_variables_initializer())
# 2001번 반복
for step in range(2001):
    cost_val, hy_val, _ = sess.run([cost, hypothesis, train],
                                   feed_dict={x1: x1_data, x2: x2_data, x3: x3_data, Y: y_data})
    if step % 10 == 0:  # 10번에 한 번씩 출력
        print(step, "Cost: ", cost_val, "\nPrediction:\n", hy_val)<jupyter_output>0 Cost:  62547.3 
Prediction:
 [-75.96344757 -78.27629089 -83.83014679 -90.80435944 -56.97648239]
10 Cost:  14.4686 
Prediction:
 [ 145.2640686   187.59541321  178.1519928   194.4858551   145.81135559]
20 Cost:  13.8225 
Prediction:
 [ 145.94779968  188.39002991  178.94906616  195.35209656  146.41212463]
30 Cost:  13.7492 
Prediction:
 [ 145.96421814  188.38262939  178.95591736  195.35777283  146.40119934]
40 Cost:  13.6763 
Prediction:
 [ 145.9785614   188.37280273  178.96031189  195.36082458  146.38844299]
50 Cost:  13.6038 
Prediction:
 [ 145.99285889  188.36302185  178.96470642  195.36386108  146.37571716]
60 Cost:  13.5317 
Prediction:
 [ 146.0071106   188.35324097  178.96910095  195.36689758  146.36302185]
70 Cost:  13.4599 
Prediction:
 [ 146.02134705  188.34352112  178.97349548  195.36994934  146.35035706]
80 Cost:  13.3887 
Prediction:
 [ 146.03552246  188.33381653  178.97784424  195.3729248   146.33773804]
90 Cost:  13.3177 
Prediction:
 [ 146.04966736  188.3241272   178.9822[...]
{'fraction_non_alphanumeric': 0.14077287066246058, 'fraction_numerical': 0.27957413249211355, 'mean_word_length': 3.7777777777777777, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '562727', 'license': 'MIT', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1136, 'n_words': 227, 'path': 'Python/tensorflow/DeepLearningZeroToAll/Lab04-1-multi_variable_linear_regression.ipynb', 'repo_name': 'statKim/TIL', 'size': '2536'}