{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"02-2-linear_regression_feed.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"code","metadata":{"id":"wgxwLdtZc7sS","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":80},"outputId":"c73e358e-2862-4878-ee93-7d65a23e4fca","executionInfo":{"status":"ok","timestamp":1577082722064,"user_tz":-540,"elapsed":2262,"user":{"displayName":"Yoon Jack","photoUrl":"","userId":"04923927567667044980"}}},"source":["import tensorflow as tf\n","tf.set_random_seed(777)"],"execution_count":1,"outputs":[{"output_type":"display_data","data":{"text/html":["

\n","The default version of TensorFlow in Colab will soon switch to TensorFlow 2.x.
\n","We recommend you upgrade now \n","or ensure your notebook will continue to use TensorFlow 1.x via the %tensorflow_version 1.x magic:\n","more info.

\n"],"text/plain":[""]},"metadata":{"tags":[]}}]},{"cell_type":"code","metadata":{"id":"O2veP8EAdHY3","colab_type":"code","colab":{}},"source":["W = tf.Variable(tf.random_normal([1]), name = 'weight')\n","b = tf.Variable(tf.random_normal([1]), name = 'bias')"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"0TQ737r1dQBe","colab_type":"code","colab":{}},"source":["X = tf.placeholder(tf.float32, shape = [None])\n","Y = tf.placeholder(tf.float32, shape = [None])"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"8JvU8vIydY4Q","colab_type":"code","colab":{}},"source":["hypothesis = X * W + b"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"NbdJ60dVdaZ_","colab_type":"code","colab":{}},"source":["cost = tf.reduce_mean(tf.square(hypothesis - Y))"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"tYXNUiy0ddcy","colab_type":"code","colab":{}},"source":["train = tf.train.GradientDescentOptimizer(learning_rate = 0.01).minimize(cost)"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"eBvaZPLJdiov","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":1000},"outputId":"e57980f5-26af-4118-b4aa-51e5f2c5b7ec","executionInfo":{"status":"ok","timestamp":1577082946941,"user_tz":-540,"elapsed":2056,"user":{"displayName":"Yoon Jack","photoUrl":"","userId":"04923927567667044980"}}},"source":["with tf.Session() as sess:\n"," sess.run(tf.global_variables_initializer())\n","\n"," for step in range(2001):\n"," _, cost_val, W_val, b_val = sess.run([train, cost, W, b],\n"," feed_dict = {X: [1, 2, 3], Y: [1, 2, 3]})\n"," \n"," if step % 20 == 0:\n"," print(step, cost_val, W_val, b_val)\n","\n","# Testing our model\n"," print(sess.run(hypothesis, feed_dict = {X: [5]}))\n"," print(sess.run(hypothesis, feed_dict = {X: [2.5]}))\n"," print(sess.run(hypothesis, feed_dict = {X: [1.5, 3.5]}))"],"execution_count":7,"outputs":[{"output_type":"stream","text":["0 3.5240757 [2.1286771] [-0.8523567]\n","20 0.19749945 [1.533928] [-1.0505961]\n","40 0.15214379 [1.4572546] [-1.0239124]\n","60 0.1379325 [1.4308538] [-0.9779527]\n","80 0.12527025 [1.4101374] [-0.93219817]\n","100 0.11377233 [1.3908179] [-0.8884077]\n","120 0.10332986 [1.3724468] [-0.8466577]\n","140 0.093845844 [1.3549428] [-0.80686814]\n","160 0.08523229 [1.3382617] [-0.7689483]\n","180 0.077409334 [1.3223647] [-0.7328106]\n","200 0.07030441 [1.3072149] [-0.69837123]\n","220 0.06385163 [1.2927768] [-0.66555053]\n","240 0.057991102 [1.2790174] [-0.6342722]\n","260 0.052668452 [1.2659047] [-0.6044637]\n","280 0.047834318 [1.2534081] [-0.57605624]\n","300 0.043443877 [1.2414987] [-0.5489836]\n","320 0.03945642 [1.2301493] [-0.5231833]\n","340 0.035834935 [1.2193329] [-0.49859545]\n","360 0.032545824 [1.2090251] [-0.47516325]\n","380 0.029558638 [1.1992016] [-0.45283225]\n","400 0.026845641 [1.18984] [-0.4315508]\n","420 0.024381675 [1.1809182] [-0.41126958]\n","440 0.02214382 [1.1724157] [-0.39194146]\n","460 0.020111356 [1.1643128] [-0.37352163]\n","480 0.018265454 [1.1565907] [-0.35596743]\n","500 0.016588978 [1.1492316] [-0.33923826]\n","520 0.015066384 [1.1422179] [-0.3232953]\n","540 0.01368351 [1.1355343] [-0.30810148]\n","560 0.012427575 [1.1291647] [-0.29362184]\n","580 0.011286932 [1.1230947] [-0.2798227]\n","600 0.010250964 [1.1173096] [-0.26667204]\n","620 0.009310094 [1.1117964] [-0.25413945]\n","640 0.008455581 [1.1065423] [-0.24219586]\n","660 0.0076795053 [1.1015354] [-0.23081362]\n","680 0.006974643 [1.0967635] [-0.21996623]\n","700 0.0063344706 [1.0922159] [-0.20962858]\n","720 0.0057530706 [1.0878822] [-0.19977672]\n","740 0.0052250377 [1.0837522] [-0.19038804]\n","760 0.004745458 [1.0798159] [-0.18144041]\n","780 0.004309906 [1.076065] [-0.17291337]\n","800 0.003914324 [1.0724902] [-0.16478711]\n","820 0.0035550483 [1.0690835] [-0.1570428]\n","840 0.0032287557 [1.0658368] [-0.14966238]\n","860 0.0029324207 [1.0627428] [-0.14262886]\n","880 0.0026632638 [1.0597941] [-0.13592596]\n","900 0.002418817 [1.056984] [-0.12953791]\n","920 0.0021968156 [1.0543059] [-0.12345009]\n","940 0.0019951805 [1.0517538] [-0.11764839]\n","960 0.0018120528 [1.0493215] [-0.11211935]\n","980 0.0016457397 [1.0470036] [-0.10685016]\n","1000 0.0014946867 [1.0447946] [-0.10182857]\n","1020 0.0013574949 [1.0426894] [-0.09704302]\n","1040 0.0012329 [1.0406834] [-0.09248242]\n","1060 0.0011197374 [1.038771] [-0.08813604]\n","1080 0.0010169642 [1.036949] [-0.08399393]\n","1100 0.0009236249 [1.0352125] [-0.08004652]\n","1120 0.00083884696 [1.0335577] [-0.07628458]\n","1140 0.0007618551 [1.0319806] [-0.07269946]\n","1160 0.00069192844 [1.0304776] [-0.06928285]\n","1180 0.0006284193 [1.0290452] [-0.06602678]\n","1200 0.000570741 [1.0276802] [-0.06292374]\n","1220 0.0005183539 [1.0263793] [-0.05996652]\n","1240 0.0004707768 [1.0251396] [-0.05714827]\n","1260 0.00042756763 [1.0239582] [-0.05446252]\n","1280 0.00038832423 [1.0228322] [-0.05190302]\n","1300 0.00035268333 [1.0217593] [-0.04946379]\n","1320 0.00032031562 [1.0207369] [-0.04713926]\n","1340 0.0002909189 [1.0197623] [-0.04492411]\n","1360 0.00026421514 [1.0188333] [-0.04281275]\n","1380 0.0002399599 [1.0179482] [-0.04080063]\n","1400 0.00021793543 [1.0171047] [-0.03888312]\n","1420 0.00019793434 [1.0163009] [-0.03705578]\n","1440 0.00017976768 [1.0155348] [-0.0353143]\n","1460 0.00016326748 [1.0148047] [-0.03365463]\n","1480 0.00014828095 [1.0141089] [-0.03207295]\n","1500 0.00013467176 [1.0134459] [-0.03056567]\n","1520 0.00012231102 [1.0128139] [-0.02912919]\n","1540 0.0001110848 [1.0122118] [-0.02776021]\n","1560 0.00010089059 [1.0116379] [-0.02645562]\n","1580 9.162969e-05 [1.011091] [-0.02521232]\n","1600 8.32208e-05 [1.0105698] [-0.0240275]\n","1620 7.558159e-05 [1.0100728] [-0.02289827]\n","1640 6.8643996e-05 [1.0095996] [-0.02182203]\n","1660 6.234226e-05 [1.0091484] [-0.02079644]\n","1680 5.662038e-05 [1.0087185] [-0.01981908]\n","1700 5.142322e-05 [1.0083088] [-0.01888768]\n","1720 4.6704197e-05 [1.0079182] [-0.01800001]\n","1740 4.2417145e-05 [1.0075461] [-0.01715407]\n","1760 3.8524515e-05 [1.0071915] [-0.01634789]\n","1780 3.4988276e-05 [1.0068535] [-0.01557962]\n","1800 3.1776715e-05 [1.0065314] [-0.01484741]\n","1820 2.886e-05 [1.0062244] [-0.0141496]\n","1840 2.621177e-05 [1.005932] [-0.01348464]\n","1860 2.380544e-05 [1.0056531] [-0.01285094]\n","1880 2.1620841e-05 [1.0053875] [-0.012247]\n","1900 1.9636196e-05 [1.0051342] [-0.01167146]\n","1920 1.7834054e-05 [1.004893] [-0.01112291]\n","1940 1.6197106e-05 [1.0046631] [-0.01060018]\n","1960 1.4711059e-05 [1.004444] [-0.01010205]\n","1980 1.3360998e-05 [1.0042351] [-0.00962736]\n","2000 1.21343355e-05 [1.0040361] [-0.00917497]\n","[5.0110054]\n","[2.500915]\n","[1.4968792 3.5049512]\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"k7zjRm-Rd_0K","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":1000},"outputId":"972ee4e8-9fc2-47ad-f4ff-5f5115cbb5aa","executionInfo":{"status":"ok","timestamp":1577083090198,"user_tz":-540,"elapsed":1759,"user":{"displayName":"Yoon Jack","photoUrl":"","userId":"04923927567667044980"}}},"source":["with tf.Session() as sess:\n"," sess.run(tf.global_variables_initializer())\n","\n"," for step in range(2001):\n"," _, cost_val, W_val, b_val = sess.run([train, cost, W, b],\n"," feed_dict = {X: [1, 2, 3, 4, 5], Y: [2.1, 3.1, 4.1, 5.1, 6.1]})\n"," \n"," if step % 20 ==0:\n"," print(step, cost_val, W_val, b_val)\n","\n","#Testing our model\n"," print(sess.run(hypothesis, feed_dict = {X: [5]}))\n"," print(sess.run(hypothesis, feed_dict = {X: [2.5]}))\n"," print(sess.run(hypothesis, feed_dict = {X: [1.5, 3.5]}))"],"execution_count":8,"outputs":[{"output_type":"stream","text":["0 5.8308015 [2.0579872] [-0.85453004]\n","20 0.6974431 [1.5424856] [-0.85012025]\n","40 0.6089927 [1.5049422] [-0.72296363]\n","60 0.53183776 [1.471864] [-0.60357887]\n","80 0.46445793 [1.4409612] [-0.4920101]\n","100 0.4056146 [1.4120823] [-0.38774815]\n","120 0.3542262 [1.3850948] [-0.29031438]\n","140 0.3093485 [1.3598746] [-0.19926159]\n","160 0.2701563 [1.3363061] [-0.11417193]\n","180 0.23592949 [1.3142811] [-0.03465483]\n","200 0.20603895 [1.2936987] [0.03965459]\n","220 0.17993543 [1.2744641] [0.10909742]\n","240 0.15713891 [1.2564892] [0.17399241]\n","260 0.13723065 [1.2396916] [0.23463738]\n","280 0.11984453 [1.223994] [0.2913106]\n","300 0.10466115 [1.2093245] [0.34427223]\n","320 0.09140136 [1.1956155] [0.39376548]\n","340 0.07982149 [1.1828046] [0.44001734]\n","360 0.06970868 [1.1708326] [0.48324007]\n","380 0.060877156 [1.1596446] [0.52363217]\n","400 0.05316441 [1.1491894] [0.561379]\n","420 0.04642888 [1.1394188] [0.59665364]\n","440 0.040546715 [1.1302881] [0.62961817]\n","460 0.035409737 [1.1217555] [0.66042393]\n","480 0.03092359 [1.1137817] [0.689212]\n","500 0.027005825 [1.10633] [0.7161149]\n","520 0.023584396 [1.0993664] [0.74125576]\n","540 0.020596411 [1.0928588] [0.7647502]\n","560 0.017987013 [1.0867774] [0.7867059]\n","580 0.01570819 [1.0810943] [0.80722374]\n","600 0.0137180565 [1.0757834] [0.82639784]\n","620 0.011980086 [1.0708202] [0.84431636]\n","640 0.010462308 [1.0661821] [0.8610613]\n","660 0.0091368025 [1.0618479] [0.87670964]\n","680 0.007979239 [1.0577973] [0.8913331]\n","700 0.0069683366 [1.0540123] [0.9049987]\n","720 0.006085513 [1.0504749] [0.9177695]\n","740 0.005314522 [1.0471693] [0.9297039]\n","760 0.0046412046 [1.0440801] [0.94085664]\n","780 0.0040532164 [1.0411934] [0.951279]\n","800 0.0035397063 [1.0384955] [0.9610188]\n","820 0.003091255 [1.0359745] [0.9701207]\n","840 0.0026996029 [1.0336185] [0.9786266]\n","860 0.0023576044 [1.0314169] [0.9865753]\n","880 0.0020589086 [1.0293593] [0.99400353]\n","900 0.0017980542 [1.0274365] [1.0009454]\n","920 0.0015702493 [1.0256397] [1.0074325]\n","940 0.0013713175 [1.0239606] [1.0134948]\n","960 0.0011975795 [1.0223913] [1.0191603]\n","980 0.0010458541 [1.0209249] [1.0244545]\n","1000 0.0009133538 [1.0195545] [1.0294019]\n","1020 0.0007976346 [1.0182738] [1.0340255]\n","1040 0.00069658464 [1.0170771] [1.0383463]\n","1060 0.00060832873 [1.0159587] [1.0423841]\n","1080 0.00053125795 [1.0149136] [1.0461575]\n","1100 0.0004639524 [1.0139369] [1.0496835]\n","1120 0.00040517404 [1.0130241] [1.0529788]\n","1140 0.00035384114 [1.0121711] [1.0560583]\n","1160 0.00030900928 [1.011374] [1.0589362]\n","1180 0.00026985919 [1.0106292] [1.0616255]\n","1200 0.00023567276 [1.009933] [1.0641385]\n","1220 0.00020581244 [1.0092824] [1.0664873]\n","1240 0.00017973856 [1.0086745] [1.0686821]\n","1260 0.00015696506 [1.0081065] [1.070733]\n","1280 0.00013708005 [1.0075755] [1.0726496]\n","1300 0.00011971353 [1.0070795] [1.0744407]\n","1320 0.00010454924 [1.0066159] [1.0761147]\n","1340 9.130365e-05 [1.0061824] [1.0776789]\n","1360 7.97329e-05 [1.0057776] [1.079141]\n","1380 6.962831e-05 [1.0053991] [1.0805074]\n","1400 6.080808e-05 [1.0050455] [1.0817839]\n","1420 5.3103977e-05 [1.0047151] [1.0829768]\n","1440 4.6376103e-05 [1.0044063] [1.0840918]\n","1460 4.0500865e-05 [1.0041177] [1.0851337]\n","1480 3.536807e-05 [1.0038481] [1.0861073]\n","1500 3.0887553e-05 [1.0035961] [1.087017]\n","1520 2.6976131e-05 [1.0033605] [1.0878673]\n","1540 2.3557152e-05 [1.0031406] [1.0886618]\n","1560 2.0572974e-05 [1.0029348] [1.0894043]\n","1580 1.7966173e-05 [1.0027426] [1.0900985]\n","1600 1.5689327e-05 [1.002563] [1.0907469]\n","1620 1.3702239e-05 [1.0023952] [1.0913529]\n","1640 1.1966238e-05 [1.0022383] [1.0919192]\n","1660 1.0450633e-05 [1.0020916] [1.0924485]\n","1680 9.125831e-06 [1.0019546] [1.0929431]\n","1700 7.970442e-06 [1.0018266] [1.0934051]\n","1720 6.959861e-06 [1.001707] [1.093837]\n","1740 6.0789594e-06 [1.0015953] [1.0942405]\n","1760 5.308894e-06 [1.0014908] [1.0946176]\n","1780 4.6360956e-06 [1.0013931] [1.0949703]\n","1800 4.0486516e-06 [1.0013019] [1.0952998]\n","1820 3.5356989e-06 [1.0012167] [1.0956075]\n","1840 3.0877115e-06 [1.001137] [1.0958952]\n","1860 2.6965522e-06 [1.0010625] [1.0961639]\n","1880 2.3551718e-06 [1.000993] [1.0964149]\n","1900 2.056715e-06 [1.0009279] [1.0966498]\n","1920 1.7962562e-06 [1.0008672] [1.0968691]\n","1940 1.5687592e-06 [1.0008105] [1.097074]\n","1960 1.3700877e-06 [1.0007573] [1.0972656]\n","1980 1.1968872e-06 [1.0007079] [1.0974445]\n","2000 1.0450387e-06 [1.0006615] [1.0976118]\n","[6.1009192]\n","[3.5992656]\n","[2.5986042 4.599927 ]\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"7qQQTdgXei28","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]}]}