<jupyter_start><jupyter_text>Lecture 4 - Multivariable linear regression Hypothesis - if there is one x    - \\(H(x) = Wx + b\\)- if there are more x     - \\(H(x_1,x_2,x_3) = W_1x_1 + W_2x_2 + W_3x_3 + b\\)     Cost function- \\( cost(W,b) = \frac{1}{m}\sum_{i=1}^{m} (H(x_1^i, x_2^i, x_3^i) - y^i)^2 \\) - Matrix Hypothesis using matrix- \\((x_1,x_2,x_3) * \left( \begin{array}{c}W_{1}\\W_{2}\\W_{3}\\\end{array}\right) = (x_1W_1 + x_2W_2 + x_3W_3)\\)- if there are a lot instance    - \\(\left( \begin{array}{c}x_{11} x_{12} x_{13}\\x_{21} x_{22} x_{23}\\x_{31} x_{32} x_{33}\\x_{41} x_{42} x_{43}\\x_{51} x_{52} x_{53}\\\end{array}\right) * \left( \begin{array}{c}W_{1}\\W_{2}\\W_{3}\\\end{array}\right) = \left( \begin{array}{c}x_{11}W_1 + x_{12}W_2 + x_{13}W_3\\x_{21}W_1+ x_{22}W_2+ x_{23}W_3\\x_{31}W_1+ x_{32}W_2+ x_{33}W_3\\x_{41}W_1+ x_{42}W_2+ x_{43}W_3\\x_{51}W_1+ x_{52}W_2+ x_{53}W_3\\\end{array}\right)\\)    - [5,3] * [3,1] = [5,1]        - \\(H(X) = XW\\) example| x_1    	|   x_2 	|   x_3 	|   Y   	||:--------:	|----------	|:--------:	|----------	|| 73       	| 80       	| 75       	| 152       || 93       	| 88       	| 93       	| 185       || 89       	| 91       	|90        	| 180      	|| 96       	| 98       	|100       	| 196      	|| 73       	| 66       	|70       	| 142      	|<jupyter_code>import tensorflow as tf
# without Matrix

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.]

x1 = tf.placeholder("float32")
x2 = tf.placeholder("float32")
x3 = tf.placeholder("float32")
Y = tf.placeholder("float32")

w1 = tf.Variable(tf.random_normal([1]), name = 'weight1')
w2 = tf.Variable(tf.random_normal([1]), name = 'weight1')
w3 = tf.Variable(tf.random_normal([1]), name = 'weight1')
b = tf.Variable(tf.random_normal([1]), name = 'bias')

hypothesis = x1 * w1 + x2 * w2 + x3 * w3 + b
cost = tf.reduce_mean(tf.square(hypothesis - Y))
optimizer = tf.train.GradientDescentOptimizer(learning_rate = 1e-5)
train = optimizer.minimize(cost)

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

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:
        print(step, "Cost: ",cost_val,"\nprediction:\n",hy_val,"\n")
        

#with Matrix

x_data = [[73.,80.,75.,],
          [93.,88.,93.,],
          [89.,91.,90.,],
          [96.,98.,100.,],
          [73.,66.,70.,]]

y_data = [[152.],
          [185.],
          [180.],
          [196.],
          [142.]]

#필요할때 마다 추가가 가능하도록 None 설정 
X = tf.placeholder("float32",shape=[None,3]) 
Y = tf.placeholder("float32",shape=[None,1])
W = tf.Variable(tf.random_normal([3,1]), name='weight')
b = tf.Variable(tf.random_normal([1]), name='bias')

hypothesis = tf.matmul(X,W) + b

cost = tf.reduce_mean(tf.square(hypothesis - Y))
optimizer = tf.train.GradientDescentOptimizer(learning_rate = 1e-5)
train = optimizer.minimize(cost)

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

for step in range(2001):
    cost_val, hy_val, _ = sess.run([cost, hypothesis, train],
                                  feed_dict = {X:x_data, Y:y_data})
    if step % 10 == 0:
        print(step, "Cost: ",cost_val,"\nprediction:\n",hy_val,"\n")<jupyter_output>0 Cost:  5349.752 
prediction:
 [[ 91.76569 ]
 [103.14121 ]
 [105.32887 ]
 [114.99363 ]
 [ 76.563644]] 

10 Cost:  16.732376 
prediction:
 [[156.35143]
 [180.79752]
 [181.82988]
 [198.30263]
 [135.80197]] 

20 Cost:  16.597311 
prediction:
 [[156.53157]
 [181.043  ]
 [182.0567 ]
 [198.55098]
 [135.99533]] 

30 Cost:  16.511494 
prediction:
 [[156.51686]
 [181.05423]
 [182.05276]
 [198.548  ]
 [136.01   ]] 

40 Cost:  16.426178 
prediction:
 [[156.50162]
 [181.06473]
 [182.04814]
 [198.5443 ]
 [136.02408]] 

50 Cost:  16.341293 
prediction:
 [[156.4864 ]
 [181.07518]
 [182.04352]
 [198.54059]
 [136.03813]] 

60 Cost:  16.256824 
prediction:
 [[156.47122]
 [181.08563]
 [182.03893]
 [198.53688]
 [136.05214]] 

70 Cost:  16.172894 
prediction:
 [[156.45612]
 [181.09604]
 [182.03435]
 [198.53319]
 [136.06612]] 

80 Cost:  16.089342 
prediction:
 [[156.44102]
 [181.10643]
 [182.02977]
 [198.52953]
 [136.08006]] 

90 Cost:  16.006311 
prediction:
 [[156.42598]
 [181.11678]
 [182.0252 ]
 [198.[...]
{'fraction_non_alphanumeric': 0.21986301369863015, 'fraction_numerical': 0.18013698630136987, 'mean_word_length': 2.6630434782608696, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '56982', 'license': 'MIT', 'n_tokens_mistral': 2404, 'n_tokens_neox': 1948, 'n_words': 333, 'path': 'Lecture4 Multivariable linear regression.ipynb', 'repo_name': 'che9992/DeepLeaningZeroToAll', 'size': '4380'}