{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##### 교재 페이지 (148-149) #####"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "6-2) matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From C:\\Users\\jsdata00010\\Anaconda3\\lib\\site-packages\\tensorflow\\python\\framework\\op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n",
      "0 Cost:  15320.755 \n",
      "Prediction:\n",
      " [[-42.37143 ]\n",
      " [-49.9997  ]\n",
      " [-51.354637]\n",
      " [-55.203167]\n",
      " [-57.852077]\n",
      " [-74.300415]\n",
      " [-75.81849 ]\n",
      " [-68.26634 ]\n",
      " [-89.54002 ]]\n",
      "10000 Cost:  16.23153 \n",
      "Prediction:\n",
      " [[35.26634 ]\n",
      " [40.94182 ]\n",
      " [45.52548 ]\n",
      " [49.496647]\n",
      " [51.258404]\n",
      " [69.95748 ]\n",
      " [71.77668 ]\n",
      " [63.04966 ]\n",
      " [87.43705 ]]\n",
      "20000 Cost:  13.404957 \n",
      "Prediction:\n",
      " [[34.873634]\n",
      " [41.90531 ]\n",
      " [44.972748]\n",
      " [49.36367 ]\n",
      " [51.43707 ]\n",
      " [70.12926 ]\n",
      " [71.6353  ]\n",
      " [63.042015]\n",
      " [87.37891 ]]\n",
      "30000 Cost:  11.16961 \n",
      "Prediction:\n",
      " [[34.52546 ]\n",
      " [42.76284 ]\n",
      " [44.481853]\n",
      " [49.245743]\n",
      " [51.596294]\n",
      " [70.28148 ]\n",
      " [71.50909 ]\n",
      " [63.035088]\n",
      " [87.32593 ]]\n",
      "40000 Cost:  9.401882 \n",
      "Prediction:\n",
      " [[34.215824]\n",
      " [43.525368]\n",
      " [44.045315]\n",
      " [49.14087 ]\n",
      " [51.73787 ]\n",
      " [70.416855]\n",
      " [71.39686 ]\n",
      " [63.028942]\n",
      " [87.278854]]\n",
      "50000 Cost:  8.00386 \n",
      "Prediction:\n",
      " [[33.9405  ]\n",
      " [44.203514]\n",
      " [43.65713 ]\n",
      " [49.047634]\n",
      " [51.8638  ]\n",
      " [70.537254]\n",
      " [71.29707 ]\n",
      " [63.023483]\n",
      " [87.236984]]\n",
      "60000 Cost:  6.89825 \n",
      "Prediction:\n",
      " [[33.6957  ]\n",
      " [44.806602]\n",
      " [43.31197 ]\n",
      " [48.96476 ]\n",
      " [51.975822]\n",
      " [70.644356]\n",
      " [71.20837 ]\n",
      " [63.01867 ]\n",
      " [87.19979 ]]\n",
      "70000 Cost:  6.023898 \n",
      "Prediction:\n",
      " [[33.477913]\n",
      " [45.3428  ]\n",
      " [43.004932]\n",
      " [48.890972]\n",
      " [52.07533 ]\n",
      " [70.739494]\n",
      " [71.12937 ]\n",
      " [63.014282]\n",
      " [87.16661 ]]\n",
      "80000 Cost:  5.332395 \n",
      "Prediction:\n",
      " [[33.284317]\n",
      " [45.819706]\n",
      " [42.731945]\n",
      " [48.825397]\n",
      " [52.163876]\n",
      " [70.824135]\n",
      " [71.05914 ]\n",
      " [63.01041 ]\n",
      " [87.13711 ]]\n",
      "90000 Cost:  4.7856045 \n",
      "Prediction:\n",
      " [[33.112003]\n",
      " [46.24361 ]\n",
      " [42.489117]\n",
      " [48.76704 ]\n",
      " [52.242542]\n",
      " [70.89944 ]\n",
      " [70.996765]\n",
      " [63.00697 ]\n",
      " [87.11104 ]]\n",
      "100000 Cost:  4.353171 \n",
      "Prediction:\n",
      " [[32.958973]\n",
      " [46.62072 ]\n",
      " [42.273323]\n",
      " [48.71525 ]\n",
      " [52.312607]\n",
      " [70.96642 ]\n",
      " [70.94131 ]\n",
      " [63.003967]\n",
      " [87.08778 ]]\n",
      "110000 Cost:  4.0110664 \n",
      "Prediction:\n",
      " [[32.823093]\n",
      " [46.95635 ]\n",
      " [42.081554]\n",
      " [48.669308]\n",
      " [52.375057]\n",
      " [71.02598 ]\n",
      " [70.89196 ]\n",
      " [63.00136 ]\n",
      " [87.06697 ]]\n",
      "120000 Cost:  3.7407138 \n",
      "Prediction:\n",
      " [[32.702038]\n",
      " [47.254303]\n",
      " [41.910892]\n",
      " [48.62829 ]\n",
      " [52.43032 ]\n",
      " [71.078835]\n",
      " [70.84803 ]\n",
      " [62.998886]\n",
      " [87.04851 ]]\n",
      "130000 Cost:  3.5270166 \n",
      "Prediction:\n",
      " [[32.594433]\n",
      " [47.519093]\n",
      " [41.75925 ]\n",
      " [48.591877]\n",
      " [52.47949 ]\n",
      " [71.12594 ]\n",
      " [70.80913 ]\n",
      " [62.996777]\n",
      " [87.03231 ]]\n",
      "140000 Cost:  3.3580005 \n",
      "Prediction:\n",
      " [[32.498867]\n",
      " [47.754536]\n",
      " [41.62445 ]\n",
      " [48.559467]\n",
      " [52.52316 ]\n",
      " [71.1676  ]\n",
      " [70.77432 ]\n",
      " [62.99477 ]\n",
      " [87.01757 ]]\n",
      "150000 Cost:  3.2241697 \n",
      "Prediction:\n",
      " [[32.41367 ]\n",
      " [47.96407 ]\n",
      " [41.50442 ]\n",
      " [48.53065 ]\n",
      " [52.562054]\n",
      " [71.204895]\n",
      " [70.74354 ]\n",
      " [62.9931  ]\n",
      " [87.004776]]\n",
      "160000 Cost:  3.1181645 \n",
      "Prediction:\n",
      " [[32.337746]\n",
      " [48.150616]\n",
      " [41.397507]\n",
      " [48.504993]\n",
      " [52.59669 ]\n",
      " [71.23818 ]\n",
      " [70.71621 ]\n",
      " [62.99165 ]\n",
      " [86.993546]]\n",
      "170000 Cost:  3.0342064 \n",
      "Prediction:\n",
      " [[32.270657]\n",
      " [48.317078]\n",
      " [41.30261 ]\n",
      " [48.482285]\n",
      " [52.627686]\n",
      " [71.26753 ]\n",
      " [70.69159 ]\n",
      " [62.990288]\n",
      " [86.98288 ]]\n",
      "180000 Cost:  2.9679677 \n",
      "Prediction:\n",
      " [[32.211304]\n",
      " [48.46487 ]\n",
      " [41.218563]\n",
      " [48.46226 ]\n",
      " [52.655285]\n",
      " [71.2936  ]\n",
      " [70.66981 ]\n",
      " [62.98915 ]\n",
      " [86.9734  ]]\n",
      "190000 Cost:  2.9156418 \n",
      "Prediction:\n",
      " [[32.15726 ]\n",
      " [48.595116]\n",
      " [41.14301 ]\n",
      " [48.443886]\n",
      " [52.679176]\n",
      " [71.31704 ]\n",
      " [70.650665]\n",
      " [62.987972]\n",
      " [86.966   ]]\n",
      "200000 Cost:  2.8743722 \n",
      "Prediction:\n",
      " [[32.1107  ]\n",
      " [48.711536]\n",
      " [41.07696 ]\n",
      " [48.42818 ]\n",
      " [52.700962]\n",
      " [71.33752 ]\n",
      " [70.63346 ]\n",
      " [62.98708 ]\n",
      " [86.9584  ]]\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "x_data = [[19., 16.6, 13.], [23., 18.4, 10.], [26., 17.1, 12.],\n",
    "          [29., 17.1, 10.], [30., 18.2, 10.], [43.,18.8, 7.],\n",
    "          [44., 19.2, 8.], [38., 18.9, 9.], [55., 19.5, 5.]]\n",
    "y_data = [[33.], [51.], [40.], [49.], [50.], [69.], [70.], \n",
    "          [64.], [89.]] \n",
    "\n",
    "# placeholders for a tensor that will be always fed.\n",
    "X = tf.placeholder(tf.float32, shape=[None, 3])\n",
    "Y = tf.placeholder(tf.float32, shape=[None, 1])\n",
    "\n",
    "W = tf.Variable(tf.random_normal([3, 1]), name='weight')\n",
    "b = tf.Variable(tf.random_normal([1]), name='bias')\n",
    "\n",
    "# Hypothesis\n",
    "hypothesis = tf.matmul(X, W) + b\n",
    "\n",
    "# Simplified cost/loss function\n",
    "cost = tf.reduce_mean(tf.square(hypothesis - Y))\n",
    "\n",
    "# Minimize\n",
    "optimizer = tf.train.GradientDescentOptimizer(learning_rate=1e-5)\n",
    "train = optimizer.minimize(cost)\n",
    "\n",
    "# Launch the graph in a session.\n",
    "sess = tf.Session()\n",
    "\n",
    "# Initializes global variables in the graph.\n",
    "sess.run(tf.global_variables_initializer())\n",
    "for step in range(200001):\n",
    "    cost_val, hy_val, _ = sess.run([cost, hypothesis, train],\n",
    "                                   feed_dict={X: x_data, Y: y_data})\n",
    "    if step % 10000 == 0:\n",
    "        print(step, \"Cost: \", cost_val, \"\\nPrediction:\\n\", hy_val)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
