<jupyter_start><jupyter_text>multi variable에 대한 linear regression의 코드를 리뷰해보자    1. 변수의 갯수에 따라 일일이 코딩하지 않도록 매트릭스 연산으로 처리<jupyter_code>import tensorflow as tf
import numpy as np

tf.set_random_seed(777)  # for reproducibility
x_data = [[73., 80., 75.],
          [93., 88., 93.],
          [89., 91., 90.],
          [96., 98., 100.],
          [73., 66., 70.]]
y_data = [[152.],
          [185.],
          [180.],
          [196.],
          [142.]]
X = tf.placeholder(tf.float32, shape=[None, 3])
Y = tf.placeholder(tf.float32, shape=[None, 1])
W = tf.Variable(tf.random_normal([3, 1]), name='weight')
b = tf.Variable(tf.random_normal([1]), name='bias')
# Hypothesis / y hat
y_hat = tf.matmul(X, W) + b
# cost/loss function
loss = tf.reduce_mean(tf.square(y_hat - Y)) # sum of the squares
# optimizer
optimizer = tf.train.GradientDescentOptimizer(learning_rate=1e-5)
train = optimizer.minimize(loss)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
W_hist = tf.summary.histogram("Weight", W)
b_hist = tf.summary.histogram("bias", b)

y_hat_hist = tf.summary.histogram("hypothesis", y_hat)

loss_scal = tf.summary.scalar("loss", loss)

# tensorboard --logdir=./logs/linear_regression_logs
merged_summary = tf.summary.merge_all()
writer = tf.summary.FileWriter("./logs/multi_variable_linear_regression_r0_02")
writer.add_graph(sess.graph)  # Show the graph
for step in range(2001):
    summary, loss_value, y_hat_value, _ = sess.run([merged_summary, loss, y_hat, train], {X: x_data, Y: y_data})

    if step % 100 == 0:
        print(step, "loss: ", loss_value, "\nPrediction: ", y_hat_value)

    writer.add_summary(summary, global_step=step)
# 대충 x1, x2, x3 값을 넣고 y 값을 prediction 해보자
x_test = [[87., 82., 91.]]
y_hat_value = sess.run([y_hat], {X: x_test})
print("X : ", x_test, "\nPrediction: ", y_hat_value[0])<jupyter_output>X :  [[87.0, 82.0, 91.0]] 
Prediction:  [[ 178.82533264]]
{'fraction_non_alphanumeric': 0.16788702928870292, 'fraction_numerical': 0.053347280334728034, 'mean_word_length': 3.806532663316583, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '365316', 'license': 'MIT', 'n_tokens_mistral': 856, 'n_tokens_neox': 802, 'n_words': 165, 'path': 'code/multi_variable_linear_regression_02_matrix.ipynb', 'repo_name': 'zeran4/justdoit', 'size': '1912'}