Skip to content

Commit

Permalink
nbfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkDaoust committed Mar 27, 2020
1 parent 5a10608 commit b8d7f9e
Show file tree
Hide file tree
Showing 99 changed files with 38,109 additions and 25,258 deletions.
146 changes: 73 additions & 73 deletions Course 1 - Part 2 - Lesson 2 - Notebook.ipynb
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Colab1-for-deeplearn.ipynb",
"provenance": [],
"toc_visible": true,
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/lmoroney/dlaicourse/blob/master/Course%201%20-%20Part%202%20-%20Lesson%202%20-%20Notebook.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
Expand All @@ -36,12 +22,14 @@
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"cellView": "form",
"colab": {},
"colab_type": "code",
"id": "BZSlp3DAjdYf",
"colab": {}
"id": "BZSlp3DAjdYf"
},
"outputs": [],
"source": [
"#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
Expand All @@ -54,15 +42,13 @@
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License."
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "ZIAkIlfmCe1B",
"colab_type": "text"
"colab_type": "text",
"id": "ZIAkIlfmCe1B"
},
"source": [
"# The Hello World of Deep Learning with Neural Networks"
Expand All @@ -71,8 +57,8 @@
{
"cell_type": "markdown",
"metadata": {
"id": "fA93WUy1zzWf",
"colab_type": "text"
"colab_type": "text",
"id": "fA93WUy1zzWf"
},
"source": [
"Like every first app you should start with something super simple that shows the overall scaffolding for how your code works. \n",
Expand All @@ -95,8 +81,8 @@
{
"cell_type": "markdown",
"metadata": {
"id": "DzbtdRcZDO9B",
"colab_type": "text"
"colab_type": "text",
"id": "DzbtdRcZDO9B"
},
"source": [
"## Imports\n",
Expand All @@ -110,24 +96,24 @@
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"id": "X9uIpOS2zx7k",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "X9uIpOS2zx7k"
},
"outputs": [],
"source": [
"import tensorflow as tf\n",
"import numpy as np\n",
"from tensorflow import keras"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "wwJGmDrQ0EoB",
"colab_type": "text"
"colab_type": "text",
"id": "wwJGmDrQ0EoB"
},
"source": [
"## Define and Compile the Neural Network\n",
Expand All @@ -137,22 +123,22 @@
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"id": "kQFAr_xo0M4T",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "kQFAr_xo0M4T"
},
"outputs": [],
"source": [
"model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "KhjZjZ-c0Ok9",
"colab_type": "text"
"colab_type": "text",
"id": "KhjZjZ-c0Ok9"
},
"source": [
"Now we compile our Neural Network. When we do so, we have to specify 2 functions, a loss and an optimizer.\n",
Expand All @@ -172,22 +158,22 @@
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"id": "m8YQN1H41L-Y",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "m8YQN1H41L-Y"
},
"outputs": [],
"source": [
"model.compile(optimizer='sgd', loss='mean_squared_error')"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "5QyOUhFw1OUX",
"colab_type": "text"
"colab_type": "text",
"id": "5QyOUhFw1OUX"
},
"source": [
"## Providing the Data\n",
Expand All @@ -199,23 +185,23 @@
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"id": "4Dxk4q-jzEy4",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "4Dxk4q-jzEy4"
},
"outputs": [],
"source": [
"xs = np.array([-1.0, 0.0, 1.0, 2.0, 3.0, 4.0], dtype=float)\n",
"ys = np.array([-3.0, -1.0, 1.0, 3.0, 5.0, 7.0], dtype=float)"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "n_YcWRElnM_b",
"colab_type": "text"
"colab_type": "text",
"id": "n_YcWRElnM_b"
},
"source": [
"# Training the Neural Network"
Expand All @@ -224,54 +210,54 @@
{
"cell_type": "markdown",
"metadata": {
"id": "c-Jk4dG91dvD",
"colab_type": "text"
"colab_type": "text",
"id": "c-Jk4dG91dvD"
},
"source": [
"The process of training the neural network, where it 'learns' the relationship between the Xs and Ys is in the **model.fit** call. This is where it will go through the loop we spoke about above, making a guess, measuring how good or bad it is (aka the loss), using the opimizer to make another guess etc. It will do it for the number of epochs you specify. When you run this code, you'll see the loss on the right hand side."
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"id": "lpRrl7WK10Pq",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "lpRrl7WK10Pq"
},
"outputs": [],
"source": [
"model.fit(xs, ys, epochs=500)"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "kaFIr71H2OZ-",
"colab_type": "text"
"colab_type": "text",
"id": "kaFIr71H2OZ-"
},
"source": [
"Ok, now you have a model that has been trained to learn the relationshop between X and Y. You can use the **model.predict** method to have it figure out the Y for a previously unknown X. So, for example, if X = 10, what do you think Y will be? Take a guess before you run this code:"
]
},
{
"cell_type": "code",
"execution_count": 0,
"metadata": {
"id": "oxNzL4lS2Gui",
"colab": {},
"colab_type": "code",
"colab": {}
"id": "oxNzL4lS2Gui"
},
"outputs": [],
"source": [
"print(model.predict([10.0]))"
],
"execution_count": 0,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "btF2CSFH2iEX",
"colab_type": "text"
"colab_type": "text",
"id": "btF2CSFH2iEX"
},
"source": [
"You might have thought 19, right? But it ended up being a little under. Why do you think that is? \n",
Expand All @@ -281,5 +267,19 @@
"As you work with neural networks, you'll see this pattern recurring. You will almost always deal with probabilities, not certainties, and will do a little bit of coding to figure out what the result is based on the probabilities, particularly when it comes to classification.\n"
]
}
]
}
],
"metadata": {
"colab": {
"include_colab_link": true,
"name": "Course 1 - Part 2 - Lesson 2 - Notebook.ipynb",
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading

0 comments on commit b8d7f9e

Please sign in to comment.