├── README.md ├── Practice.ipynb └── Solution.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # WhatisMLwithTensorflow 2 | Practice Notebook for those Who Want to try building their first Simple Neural Network 3 | -------------------------------------------------------------------------------- /Practice.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Practice.ipynb", 7 | "version": "0.3.2", 8 | "provenance": [] 9 | }, 10 | "kernelspec": { 11 | "name": "python3", 12 | "display_name": "Python 3" 13 | } 14 | }, 15 | "cells": [ 16 | { 17 | "metadata": { 18 | "id": "96lwY9OZhzUz", 19 | "colab_type": "text" 20 | }, 21 | "cell_type": "markdown", 22 | "source": [ 23 | "#Traditional Programming" 24 | ] 25 | }, 26 | { 27 | "metadata": { 28 | "id": "E7Kr05GFhw0M", 29 | "colab_type": "text" 30 | }, 31 | "cell_type": "markdown", 32 | "source": [ 33 | "---\n", 34 | "\n", 35 | "> > > > > > **Equation --> y = 2.5 * x + 3**\n", 36 | "\n", 37 | "| x | -10 | -5 | 2 | 100 | 50 | 1000 | \n", 38 | "|---------|----------|-----------|---------|--------- |------------|--------------|\n", 39 | "| y | -22 | -9.5 | 8 | 253 | 126.5 | 2530 |\n", 40 | "\n", 41 | "---" 42 | ] 43 | }, 44 | { 45 | "metadata": { 46 | "id": "dNvDTTwmh_Dn", 47 | "colab_type": "code", 48 | "colab": {} 49 | }, 50 | "cell_type": "code", 51 | "source": [ 52 | "x = " 53 | ], 54 | "execution_count": 0, 55 | "outputs": [] 56 | }, 57 | { 58 | "metadata": { 59 | "id": "KngjDWEve7ZP", 60 | "colab_type": "code", 61 | "colab": {} 62 | }, 63 | "cell_type": "code", 64 | "source": [ 65 | "y = " 66 | ], 67 | "execution_count": 0, 68 | "outputs": [] 69 | }, 70 | { 71 | "metadata": { 72 | "id": "_aENJKIpiL79", 73 | "colab_type": "code", 74 | "colab": { 75 | "base_uri": "https://localhost:8080/", 76 | "height": 35 77 | }, 78 | "outputId": "a38b2239-8d01-4f4b-a653-b4eef9a707b4" 79 | }, 80 | "cell_type": "code", 81 | "source": [ 82 | "print(\"x = {} , y = {}\".format(x, y))" 83 | ], 84 | "execution_count": 7, 85 | "outputs": [ 86 | { 87 | "output_type": "stream", 88 | "text": [ 89 | "x = -10 , y = -22.0\n" 90 | ], 91 | "name": "stdout" 92 | } 93 | ] 94 | }, 95 | { 96 | "metadata": { 97 | "id": "RTOb9OI7iWBa", 98 | "colab_type": "text" 99 | }, 100 | "cell_type": "markdown", 101 | "source": [ 102 | "# Machine Learning with Tensorflow" 103 | ] 104 | }, 105 | { 106 | "metadata": { 107 | "id": "aM06IeJHhpTe", 108 | "colab_type": "text" 109 | }, 110 | "cell_type": "markdown", 111 | "source": [ 112 | "---\n", 113 | "\n", 114 | "> > > > > > **Equation --> y = 2.5 * x + 3**\n", 115 | "\n", 116 | "| x | -10 | -5 | 2 | 100 | 50 | 1000 | \n", 117 | "|---------|----------|-----------|---------|--------- |------------|--------------|\n", 118 | "| y | -22 | -9.5 | 8 | 253 | 126.5 | 2530 |\n", 119 | "\n", 120 | "\n", 121 | "---" 122 | ] 123 | }, 124 | { 125 | "metadata": { 126 | "id": "QOyGKKyDe-Dg", 127 | "colab_type": "text" 128 | }, 129 | "cell_type": "markdown", 130 | "source": [ 131 | "
\n", 132 | " \n", 133 | " \n", 134 | "\n", 135 | "
" 136 | ] 137 | }, 138 | { 139 | "metadata": { 140 | "id": "vGSGXOHkfAXD", 141 | "colab_type": "code", 142 | "colab": {} 143 | }, 144 | "cell_type": "code", 145 | "source": [ 146 | "import \n", 147 | "import \n", 148 | "tf.logging.set_verbosity(tf.logging.ERROR)" 149 | ], 150 | "execution_count": 0, 151 | "outputs": [] 152 | }, 153 | { 154 | "metadata": { 155 | "id": "v8fa7wy3iq8q", 156 | "colab_type": "code", 157 | "colab": {} 158 | }, 159 | "cell_type": "code", 160 | "source": [ 161 | "[-10, -5, 2, 100]\n", 162 | "[-22, -9.5, 8, 253]" 163 | ], 164 | "execution_count": 0, 165 | "outputs": [] 166 | }, 167 | { 168 | "metadata": { 169 | "id": "gY9mxB-Ti2Wn", 170 | "colab_type": "code", 171 | "colab": {} 172 | }, 173 | "cell_type": "code", 174 | "source": [ 175 | "print(\"x = {}, y={}\")" 176 | ], 177 | "execution_count": 0, 178 | "outputs": [] 179 | }, 180 | { 181 | "metadata": { 182 | "id": "vzxpnShCjDQR", 183 | "colab_type": "code", 184 | "colab": {} 185 | }, 186 | "cell_type": "code", 187 | "source": [ 188 | "layer = tf.keras.layers.Dense(units=, input_shape=[])" 189 | ], 190 | "execution_count": 0, 191 | "outputs": [] 192 | }, 193 | { 194 | "metadata": { 195 | "id": "V8IiwyH4jWu2", 196 | "colab_type": "text" 197 | }, 198 | "cell_type": "markdown", 199 | "source": [ 200 | "###Define the Model" 201 | ] 202 | }, 203 | { 204 | "metadata": { 205 | "id": "ivo9X-TfjUbA", 206 | "colab_type": "code", 207 | "colab": {} 208 | }, 209 | "cell_type": "code", 210 | "source": [ 211 | "model = tf.keras.Sequential([])" 212 | ], 213 | "execution_count": 0, 214 | "outputs": [] 215 | }, 216 | { 217 | "metadata": { 218 | "id": "4x6dJs8YjxlN", 219 | "colab_type": "text" 220 | }, 221 | "cell_type": "markdown", 222 | "source": [ 223 | "###Compile the Model" 224 | ] 225 | }, 226 | { 227 | "metadata": { 228 | "id": "Sg4sHtNYjYaM", 229 | "colab_type": "code", 230 | "colab": {} 231 | }, 232 | "cell_type": "code", 233 | "source": [ 234 | "model.compile(loss='', optimizer=tf.keras.optimizers.Adam())" 235 | ], 236 | "execution_count": 0, 237 | "outputs": [] 238 | }, 239 | { 240 | "metadata": { 241 | "id": "9MVNCGI6kEnM", 242 | "colab_type": "text" 243 | }, 244 | "cell_type": "markdown", 245 | "source": [ 246 | "###Train the Model (Fit Network)" 247 | ] 248 | }, 249 | { 250 | "metadata": { 251 | "id": "XnC5KCPejq2r", 252 | "colab_type": "code", 253 | "colab": {} 254 | }, 255 | "cell_type": "code", 256 | "source": [ 257 | "train = model.fit(, ,epochs=, verbose=False)" 258 | ], 259 | "execution_count": 0, 260 | "outputs": [] 261 | }, 262 | { 263 | "metadata": { 264 | "id": "j9VK9zYpkkFI", 265 | "colab_type": "text" 266 | }, 267 | "cell_type": "markdown", 268 | "source": [ 269 | "###Evaluate the Model" 270 | ] 271 | }, 272 | { 273 | "metadata": { 274 | "id": "jkSXImRijrCy", 275 | "colab_type": "code", 276 | "colab": {} 277 | }, 278 | "cell_type": "code", 279 | "source": [ 280 | "import matplotlib.pyplot as plt\n", 281 | "plt.plot()" 282 | ], 283 | "execution_count": 0, 284 | "outputs": [] 285 | }, 286 | { 287 | "metadata": { 288 | "id": "94kqW73ukyk9", 289 | "colab_type": "text" 290 | }, 291 | "cell_type": "markdown", 292 | "source": [ 293 | "###Test the Model(Make Predictions)" 294 | ] 295 | }, 296 | { 297 | "metadata": { 298 | "id": "hlAqqr1wk3_z", 299 | "colab_type": "code", 300 | "colab": {} 301 | }, 302 | "cell_type": "code", 303 | "source": [ 304 | "model.predict([])" 305 | ], 306 | "execution_count": 0, 307 | "outputs": [] 308 | }, 309 | { 310 | "metadata": { 311 | "id": "MW6Pt7rzk_eh", 312 | "colab_type": "code", 313 | "colab": {} 314 | }, 315 | "cell_type": "code", 316 | "source": [ 317 | "layer.get_weights()" 318 | ], 319 | "execution_count": 0, 320 | "outputs": [] 321 | } 322 | ] 323 | } -------------------------------------------------------------------------------- /Solution.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "name": "Solution.ipynb", 7 | "version": "0.3.2", 8 | "provenance": [], 9 | "collapsed_sections": [] 10 | }, 11 | "kernelspec": { 12 | "name": "python3", 13 | "display_name": "Python 3" 14 | }, 15 | "accelerator": "GPU" 16 | }, 17 | "cells": [ 18 | { 19 | "metadata": { 20 | "id": "96lwY9OZhzUz", 21 | "colab_type": "text" 22 | }, 23 | "cell_type": "markdown", 24 | "source": [ 25 | "#Traditional Programming" 26 | ] 27 | }, 28 | { 29 | "metadata": { 30 | "id": "E7Kr05GFhw0M", 31 | "colab_type": "text" 32 | }, 33 | "cell_type": "markdown", 34 | "source": [ 35 | "---\n", 36 | "\n", 37 | "> > > > > > **Equation --> y = 2.5 * x + 3**\n", 38 | "\n", 39 | "| x | -10 | -5 | 2 | 100 | 50 | 1000 | \n", 40 | "|---------|----------|-----------|---------|--------- |------------|--------------|\n", 41 | "| y | -22 | -9.5 | 8 | 253 | 126.5 | 2530 |\n", 42 | "\n", 43 | "---" 44 | ] 45 | }, 46 | { 47 | "metadata": { 48 | "id": "dNvDTTwmh_Dn", 49 | "colab_type": "code", 50 | "colab": {} 51 | }, 52 | "cell_type": "code", 53 | "source": [ 54 | "x = -10" 55 | ], 56 | "execution_count": 0, 57 | "outputs": [] 58 | }, 59 | { 60 | "metadata": { 61 | "id": "KngjDWEve7ZP", 62 | "colab_type": "code", 63 | "colab": {} 64 | }, 65 | "cell_type": "code", 66 | "source": [ 67 | "y = 2.5 * x + 3" 68 | ], 69 | "execution_count": 0, 70 | "outputs": [] 71 | }, 72 | { 73 | "metadata": { 74 | "id": "T5Khl1JUQ1wI", 75 | "colab_type": "code", 76 | "colab": {} 77 | }, 78 | "cell_type": "code", 79 | "source": [ 80 | "print(\"x = {} , y = {}\".format(x, y))" 81 | ], 82 | "execution_count": 0, 83 | "outputs": [] 84 | }, 85 | { 86 | "metadata": { 87 | "id": "RTOb9OI7iWBa", 88 | "colab_type": "text" 89 | }, 90 | "cell_type": "markdown", 91 | "source": [ 92 | "# Machine Learning with Tensorflow" 93 | ] 94 | }, 95 | { 96 | "metadata": { 97 | "id": "aM06IeJHhpTe", 98 | "colab_type": "text" 99 | }, 100 | "cell_type": "markdown", 101 | "source": [ 102 | "---\n", 103 | "\n", 104 | "> > > > > > **Equation --> y = 2.5 * x + 3**\n", 105 | "\n", 106 | "| x | -10 | -5 | 2 | 100 | 50 | 1000 | \n", 107 | "|---------|----------|-----------|---------|--------- |------------|--------------|\n", 108 | "| y | -22 | -9.5 | 8 | 253 | 126.5 | 2530 |\n", 109 | "\n", 110 | "\n", 111 | "---" 112 | ] 113 | }, 114 | { 115 | "metadata": { 116 | "id": "QOyGKKyDe-Dg", 117 | "colab_type": "text" 118 | }, 119 | "cell_type": "markdown", 120 | "source": [ 121 | "
\n", 122 | " \n", 123 | " \n", 124 | "\n", 125 | "
" 126 | ] 127 | }, 128 | { 129 | "metadata": { 130 | "id": "vGSGXOHkfAXD", 131 | "colab_type": "code", 132 | "colab": {} 133 | }, 134 | "cell_type": "code", 135 | "source": [ 136 | "import \n", 137 | "import \n", 138 | "tf.logging.set_verbosity(tf.logging.ERROR)" 139 | ], 140 | "execution_count": 0, 141 | "outputs": [] 142 | }, 143 | { 144 | "metadata": { 145 | "id": "v8fa7wy3iq8q", 146 | "colab_type": "code", 147 | "colab": {} 148 | }, 149 | "cell_type": "code", 150 | "source": [ 151 | "x = np.array([-10, -5, 2, 100], dtype=float)\n", 152 | "y = np.array([-22, -9.5, 8, 253], dtype=float)" 153 | ], 154 | "execution_count": 0, 155 | "outputs": [] 156 | }, 157 | { 158 | "metadata": { 159 | "id": "Vkj8UoDgfOvX", 160 | "colab_type": "code", 161 | "colab": {} 162 | }, 163 | "cell_type": "code", 164 | "source": [ 165 | "print(\"x = {}, y={}\".format(x, y))" 166 | ], 167 | "execution_count": 0, 168 | "outputs": [] 169 | }, 170 | { 171 | "metadata": { 172 | "id": "Z_FcZSKE5I_i", 173 | "colab_type": "text" 174 | }, 175 | "cell_type": "markdown", 176 | "source": [ 177 | "
\n", 178 | "\n", 179 | "\n", 180 | "\n", 181 | "
" 182 | ] 183 | }, 184 | { 185 | "metadata": { 186 | "id": "vzxpnShCjDQR", 187 | "colab_type": "code", 188 | "colab": {} 189 | }, 190 | "cell_type": "code", 191 | "source": [ 192 | "layer = tf.keras.layers.Dense(units=1, input_shape=[1])" 193 | ], 194 | "execution_count": 0, 195 | "outputs": [] 196 | }, 197 | { 198 | "metadata": { 199 | "id": "V8IiwyH4jWu2", 200 | "colab_type": "text" 201 | }, 202 | "cell_type": "markdown", 203 | "source": [ 204 | "###Define the Model" 205 | ] 206 | }, 207 | { 208 | "metadata": { 209 | "id": "ivo9X-TfjUbA", 210 | "colab_type": "code", 211 | "colab": {} 212 | }, 213 | "cell_type": "code", 214 | "source": [ 215 | "model = tf.keras.Sequential([layer])" 216 | ], 217 | "execution_count": 0, 218 | "outputs": [] 219 | }, 220 | { 221 | "metadata": { 222 | "id": "4x6dJs8YjxlN", 223 | "colab_type": "text" 224 | }, 225 | "cell_type": "markdown", 226 | "source": [ 227 | "###Compile the Model" 228 | ] 229 | }, 230 | { 231 | "metadata": { 232 | "id": "Sg4sHtNYjYaM", 233 | "colab_type": "code", 234 | "colab": {} 235 | }, 236 | "cell_type": "code", 237 | "source": [ 238 | "model.compile(loss='mean_squared_error', \n", 239 | " optimizer=tf.keras.optimizers.Adam(0.1))" 240 | ], 241 | "execution_count": 0, 242 | "outputs": [] 243 | }, 244 | { 245 | "metadata": { 246 | "id": "9MVNCGI6kEnM", 247 | "colab_type": "text" 248 | }, 249 | "cell_type": "markdown", 250 | "source": [ 251 | "###Train the Model (Fit Network)" 252 | ] 253 | }, 254 | { 255 | "metadata": { 256 | "id": "XnC5KCPejq2r", 257 | "colab_type": "code", 258 | "colab": {} 259 | }, 260 | "cell_type": "code", 261 | "source": [ 262 | "train = model.fit(x, y,epochs=1000, verbose=False)" 263 | ], 264 | "execution_count": 0, 265 | "outputs": [] 266 | }, 267 | { 268 | "metadata": { 269 | "id": "j9VK9zYpkkFI", 270 | "colab_type": "text" 271 | }, 272 | "cell_type": "markdown", 273 | "source": [ 274 | "###Evaluate the Model" 275 | ] 276 | }, 277 | { 278 | "metadata": { 279 | "id": "jkSXImRijrCy", 280 | "colab_type": "code", 281 | "colab": {} 282 | }, 283 | "cell_type": "code", 284 | "source": [ 285 | "import matplotlib.pyplot as plt\n", 286 | "plt.plot(train.history['loss'])" 287 | ], 288 | "execution_count": 0, 289 | "outputs": [] 290 | }, 291 | { 292 | "metadata": { 293 | "id": "94kqW73ukyk9", 294 | "colab_type": "text" 295 | }, 296 | "cell_type": "markdown", 297 | "source": [ 298 | "###Test the Model(Make Predictions)" 299 | ] 300 | }, 301 | { 302 | "metadata": { 303 | "id": "hlAqqr1wk3_z", 304 | "colab_type": "code", 305 | "outputId": "4a5e86f8-0bb6-4080-b0e4-38e271244e53", 306 | "colab": { 307 | "base_uri": "https://localhost:8080/", 308 | "height": 35 309 | } 310 | }, 311 | "cell_type": "code", 312 | "source": [ 313 | "model.predict([50])" 314 | ], 315 | "execution_count": 0, 316 | "outputs": [ 317 | { 318 | "output_type": "execute_result", 319 | "data": { 320 | "text/plain": [ 321 | "array([[128.]], dtype=float32)" 322 | ] 323 | }, 324 | "metadata": { 325 | "tags": [] 326 | }, 327 | "execution_count": 32 328 | } 329 | ] 330 | }, 331 | { 332 | "metadata": { 333 | "id": "MW6Pt7rzk_eh", 334 | "colab_type": "code", 335 | "colab": {} 336 | }, 337 | "cell_type": "code", 338 | "source": [ 339 | "layer.get_weights()" 340 | ], 341 | "execution_count": 0, 342 | "outputs": [] 343 | }, 344 | { 345 | "metadata": { 346 | "id": "UgTmKrB5d91A", 347 | "colab_type": "code", 348 | "colab": {} 349 | }, 350 | "cell_type": "code", 351 | "source": [ 352 | "" 353 | ], 354 | "execution_count": 0, 355 | "outputs": [] 356 | } 357 | ] 358 | } --------------------------------------------------------------------------------