Skip to content

Commit cee04e6

Browse files
committed
make second pass edits
1 parent 62153e1 commit cee04e6

File tree

9 files changed

+79
-44
lines changed

9 files changed

+79
-44
lines changed

responses/01-install.md

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,17 @@
1-
## Install Python
2-
As a first step, let's focus on getting Python installed and running. I am going to focus on a Windows-targeted installation; if you're using any other OS please see the OS-specific installation instructions [here](https://realpython.com/installing-python/).
3-
For a Windows installation, navigate your browser to the official python [Releases for Windows](https://www.python.org/downloads/windows/) page. Near the top of the page there should be a link to the *Latest Python 3 Release - Python 3.X.X*; click it! The simplest installation method involves downloading the executable installer and merely executing it.
4-
<div style="border:1px solid black">
5-
BRIEF NOTE ON VERSIONS AND ARCHITECTURES
6-
7-
Python is presently operating under version 3 (Python 3), yet still provides downloads and some support for Python 2. There are few linguistic differences between the versions, yet several of the more modern ML packages specifically support Python 3. Please download Python 3 for this tutorial. If you require the legacy Python 2 for any reason, both versions can be installed side-by-side.
8-
9-
Python 3 supports both 32- and 64-bit architectures, yet some of the more important ML packages only support 64-bit. So, let's focus on the 64-bit version.
10-
</div>
11-
12-
## Setting environment variables
13-
14-
Let's make an admission, Windows is stupid. And it's not just Windows, it's all operating systems! They facilitate you in finding and organizing files and executables on your machine, yet they rarely fix themselves or spontaneously learn things. This is a long way of saying that we need to manually teach Windows the command we will use to start python (and pip), and what Windows should do with that command. This is deemed 'setting environmental variables' or adding to a search path. [These](https://datatofish.com/add-python-to-windows-path/) instructions should help you teach Windows how to do what you want.
1+
*Correct!*
152

16-
## Testing Python
17-
Let's quickly verify that python is installed and that the environmental variables are set. Launch your Command Line, which can be done in Windows by search "CMD" and executing it.
18-
This will give you an "old school" DOS prompt, that black screen that no one under the age of 30 remembers, and no one under 45 remembers how to use. As a good habit, before launching Python, I set the directory to the root, which typically for Windows is the C:\ drive. This can be done by typing "cd\", meaning change director to nothing.
3+
Glad you are paying attention. 😉
194

20-
```console
21-
C:\Users\ross.hoehn>cd\
22-
C:\>
23-
```
24-
After achieving the root directory, and thanks to us setting the environmental variables above, merely typing "python" at the c-prompt will launch the Python environment. You will immediately be greeted with the version information of your Python install (mine is 3.6.7 and is 64 bit).
5+
## Install Python
6+
As a first step, let's make sure Python is installed and running. To test if it is installed and configured already, type `python` into your terminal. If it isn't installed yet, it should say something like "python is a unknown command". If it is installed, it will open the python environment, and should look something like this:
257

268
```console
27-
C:\>python
289
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 13:35:33) [MSC v.1900 64 bit (AMD64)] on win32
2910
Type "help", "copyright", "credits" or "license" for more information.
3011
>>>
3112
```
13+
If you see this type `exit()` to return to the command prompt. If not, you need install the latest Python 3 release for your OS: [Windows](https://www.python.org/downloads/windows/), [Mac](https://www.python.org/downloads/mac-osx/), [Linux/Unix](https://www.python.org/downloads/source/). After you install python, you need to add it to your PATH variable to use the `python` command shortcut. You can find directions for how to do this [here](https://www.tutorialspoint.com/python/python_environment.htm)
3214

33-
You will also know that you are in the Python environment as the prompt at which you type is represented by ">>>". Now, to install some packages for our project, we cannot do this from the Python environment, so we will need the means to leave the environment. This command is conveniently "exit()".
34-
```console
35-
>>> exit()
36-
C:\>
37-
```
15+
You will need to close and reopen you command prompt before the new environmental variable is recognized. Type `python` to check if it is set up correctly. You will also know that you are in the Python environment as the prompt at which you type is represented by ">>>". Now, to install some packages for our project, we cannot do this from the Python environment, so we will need the means to leave the environment. This command is conveniently `exit()`.
3816

3917
*close this issue if you correctly installed Python*

responses/02-import.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
## Pip Installing Packages
22

3-
To complete this project we will need a few packages; these are add-ons available to Python but not included in the base install. Very luckily, we installed the latest Python 3, which includes the Pip Installation module of Python. Pip is a fast and easy way to install packages and their dependencies. As we are doing an NN-based project, we will need to use TensorFlow. For those who only recognize TensorFlow by its association with NNs, it may be shocking to learn that TensorFlow is a more general tool for the manipulation of mathematical entities called tensors. NNs are just a single use of tenor mechanics, and therefore TensorFlow.
3+
To complete this project we will need a few packages; these are add-ons available to Python but not included in the base install. Very luckily, we installed the latest Python 3, which includes the Pip Installation module of Python. Pip is a fast and easy way to install packages and their dependencies. As we are doing an NN-based project, we will need to use TensorFlow. For those who only recognize TensorFlow by its association with NNs, it may be shocking to learn that TensorFlow is a more general tool for the manipulation of mathematical entities called tensors. NNs are just a single use of tenor mechanics, and therefore TensorFlow.
44

55
As tensors and TensorFlow can be fairly complex to manage, there exists another package named Keras that acts as a high-level API (Application Programming Interface), allowing users to easily generation, define and manipulate the structures within TensorFlow.
6+
67
Finally, as we wish to visualize aspects of our dataset and generate some informational plots, we will want Python's Mathematical Plotting Library, MatPlotLib. Additionally, MatPlotLib facilitates the generation of graphical plots in new windows, even when executed from the Command Line. And finally, to handle numerical computations and array-based operations we will import Numpy.
78

89
Starting from the c-prompt (where we left off above), you will need to tell the easy Python package manager (a program that helps you install, uninstall, update and upgrade ancillary features to a larger application) that we want to install Numpy, MatPlotLib, and Tensorflow.
10+
911
```console
10-
C:\>pip install Numpy
11-
C:\>pip install MatPlotLib
12-
C:\>pip install Tensorflow
12+
pip install Numpy
13+
pip install MatPlotLib
14+
pip install Tensorflow
1315
```
16+
17+
If you encounter a permissions error, you may need to add `--user` to the end of each install. For example `pip install Numpy --user`.
18+
1419
After each of these actions, pip will display that it is downloading and installing the package. If you have an existing (but not up-to-date) version, pip will first uninstall the old version before installing the new. If you have previously installed the current version of any package, pip will inform you that the 'requirement already exists'.
20+
1521
Now we can test if Python has installed our Tensorflow correctly (this being the testier of the three packages), by returning to the Python Environment and printing the version of our Tensorflow:
22+
1623
```console
17-
C:\>python
24+
python
1825
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 13:35:33) [MSC v.1900 64 bit (AMD64)] on win32
1926
Type "help", "copyright", "credits" or "license" for more information.
2027
>>> import tensorflow as tf

responses/02-packages.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
1+
*That's right!* Remember that TensorFlow is a more general tool for working with *tensors*. Therefore, it is not only used for Neural Networks.
2+
13
## Import Packages
2-
We will be executing all of our Python code from the Window's Command Line (CMD). Although CMD doesn't afford us syntactic color coding, it provides us with a degree of immediate responsiveness and the ability to see all messages passed during operations instead of just fail or pass state messages. Note that we have provided you syntactic color coding in this tutorial as it, generally, makes the code more readable.
4+
We will be executing all of our Python code using the command line interface and a Python interpretor. This provides us with a degree of immediate responsiveness and the ability to see all messages passed during operations instead of just fail or pass state messages.
5+
36
To import packaged into a specific Python environment, you need only use the 'import' command.
7+
48
```console
5-
C:\>python
9+
python
610
Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 13:35:33) [MSC v.1900 64 bit (AMD64)] on win32
711
Type "help", "copyright", "credits" or "license" for more information.
812
>>> import numpy
913
>>>
1014
```
15+
1116
We are also able to give packages nicknames, really useful so we don't have to type out matplotlib or tensorflow thousands of times. We assign these nicknames by "importing as".
17+
1218
```console
1319
>>> import matplotlib.pyplot as plt
1420
>>>
1521
```
22+
1623
And finally, we import Tensorflow and its Keras interface. Note that we can always call Keras as a Tensorflow object (i.e. tf.keras.command() ), but that takes too much typing. To save us time, we will import Keras from Tensorflow.
24+
1725
```console
1826
>>> import tensorflow as tf
1927
>>> from tensorflow import keras
2028
>>>
2129
```
30+
2231
All of our prerequisite packages are now installed!
2332

2433
*Leave a comment after you have imported the libraries above for the next step.*

responses/02-test-image.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Now we are ready to roll! First, we must admit that it takes a lot of data to train a NN, and 70,000 examples is an anemic dataset. So instead of doing a more traditional 70/20/10 or 80/10/10 percent split between training/validating/testing, we will do a simple 6:1 ratio of training:testing (note that this is not best practices, but when there is limited data it may be your only recourse).
33

44
We first load in the dataset from the Keras package:
5+
56
```console
67
>>> fashion_mnist = keras.datasets.fashion_mnist
78
>>> (train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
@@ -15,10 +16,12 @@ Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-dataset
1516
4423680/4422102 [==============================] - 0s 0us/step
1617
>>>
1718
```
18-
The first line merely assigns the name fashion_mnist to a particular dataset located within Keras' dataset library. The second line defines four arrays containing the training and testing data, cleaved again into separate structures for images and labels, and then loads all of that data into our standup of Python. The training data arrays will be used to (duh) train the model, and the testing arrays will allow us to evaluate the performance of our model.
19+
20+
The first line merely assigns the name fashion_mnist to a particular dataset located within Keras' dataset library. The second line defines four arrays containing the training and testing data, cleaved again into separate structures for images and labels, and then loads all of that data into our standup of Python. The training data arrays will be used to --you guessed it-- train the model, and the testing arrays will allow us to evaluate the performance of our model.
1921

2022
### Look at data
2123
It's always nice to be able to show that we've actually done something; ever since kindergarten there has been no better way than with a picture! You'll note that we pip installed and imported MatPlotLib, a library for plots and graphs. Here we'll use it to visualize an example of the Fashion MNIST dataset.
24+
2225
```console
2326
>>> plt.figure()
2427
<Figure size 640x480 with 0 Axes>
@@ -29,7 +32,9 @@ It's always nice to be able to show that we've actually done something; ever sin
2932
>>> plt.grid(False)
3033
>>> plt.show()
3134
```
35+
3236
The first command basically generates a figure object that will be manipulated by commands 2 through 4. Command 2 specifies what it is that we shall be plotting: the first element from the train_images array. *NOTE*: Recall that python is an inclusive counting language, meaning that it numbers/indexes things starting from zero, not one! And the final command, "show()", tells Python to generate this figure in an external (from CMD) window.
37+
3338
Your window should contain a plot that looks similar to Figure 3. Also, be aware that after plt.show(), Python will not return you to a command line until the newly generated window (containing our super nice picture) is closed. Upon closing the window, you will be able to continue entering Python commands.
3439

3540
![image of boot]({{repoUrl}}/raw/master/img/boot.png)

responses/03-complete.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
There you have it! You have built and trained your first neural network from scratch, and properly classified a boot as a boot!
1+
*You're right!* Remember we had ten potential articles of clothing that we were testing.
2+
3+
There you have it! You have built and trained your first neural network from scratch, and properly classified a boot as a boot!
24

35
Next Steps:
46

5-
* Try using the model on a item of clothin outside the dataset (make sure to preprocess it frist so it is on the same scale as the other images).
7+
* Try using the model on a item of clothing outside the dataset (make sure to preprocess it first so it is on the same scale as the other images).
68
* Find another [image dataset](https://blog.cambridgespark.com/50-free-machine-learning-datasets-image-datasets-241852b03b49) to try this out on.
7-
* Make an interface that responds with a label when you select a clothing image
9+
* Make an interface that responds with a label when you select a clothing image.

responses/03-eval.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
1+
*That's correct!*
2+
3+
This is why we used the train_labels array as the second argument.
4+
15
## Evaluating Our Model
26
Now we are working with a functional and trained NN model. Following our logic from the top, we have built a NN that intakes a (28,28) array, flattens the data into a (784) array, compiled and trained 2 dense layers, and the softmax activation function of the final output layer will provide a probability that the image belongs to each of the 10 label categories.
7+
38
Our model can be evaluated by using the model.evaluate command, that takes in the images and labels so that it can compare its predictions to the ground truth provided by the labels. Model.evaluate provides two outputs, the value of the loss function over the testing examples, and the accuracy of the model over this testing population. The important output for us is the model's accuracy.
9+
410
```console
511
>>> test_loss, test_acc = model.evaluate(test_images, test_labels)
612
10000/10000 [==============================] - 0s 27us/sample - loss: 0.3543 - acc: 0.8721
713
>>> print(test_acc)
814
0.8721
915
>>>
1016
```
17+
1118
This is great! Our model performs at an accuracy of 87.21%. As good as that is, it is lower than the model accuracy promised above (89.01%). This lower performance is due to the model overfitting on the training data. Overfitting occurs when there are too many parameters within the model when compared to the number of training instances; this allows the model to over learn on those limited examples. Overfitting leads to better model performance over non-training data.
1219

1320
That said, 87.21% is a decent number! Let's finally learn how you can feed our model the series of test examples from the test_images array, and have it provide its predictions.
21+
1422
```console
1523
>>> predictions = model.predict(test_images)
1624
>>> predictions[0]
1725
array([5.1039719e-04, 1.4324225e-07, 6.3209918e-06, 1.4587535e-07,
1826
7.1591121e-06, 3.9024312e-02, 3.2491367e-05, 9.4579764e-02,
1927
1.8918892e-05, 8.6582035e-01], dtype=float32)
2028
```
21-
As we can see, most of the entries in our prediction array are very close to 0. The entry that stands out is predictions[0][9] at .8658, or 86.58%, certainty that this image should be classified as a boot! This happens to be true and can be check by you if you repeat the code above to visualize test_images[0].
29+
As we can see, most of the entries in our prediction array are very close to 0. They are written in scientific notation--the value after the *e* being the number decimal places to adjust the value (for example 5.1 e-04 is actually 0.00051). The entry that stands out is predictions[0][9] at .8658, or 86.58%, certainty that this image should be classified as a boot!
2230

2331
If you prefer to not look through a list to determine the class label, we can simplify the output by:
32+
2433
```console
2534
>>> numpy.argmax(predictions[0])
2635
9
2736
>>>
2837
```
38+
2939
Finally, we can verify this prediction by looking at the label ourselves:
40+
3041
```console
3142
>>> test_labels[0]
3243
9
@@ -36,16 +47,18 @@ Finally, we can verify this prediction by looking at the label ourselves:
3647
*To complete this course, leave a comment with the letter (A,B,C,D) that best answers the following question:*
3748

3849
In the prediction array generated by our model:
50+
3951
```
4052
>>> predictions = model.predict(test_images)
4153
>>> predictions[0]
4254
array([5.1039719e-04, 1.4324225e-07, 6.3209918e-06, 1.4587535e-07,
4355
7.1591121e-06, 3.9024312e-02, 3.2491367e-05, 9.4579764e-02,
4456
1.8918892e-05, 8.6582035e-01], dtype=float32)
4557
```
58+
4659
_each number_ represents:
4760

4861
A. The probability that the image is a boot
49-
B. Average pixle values (between 0 and 1)
62+
B. Average pixel values (between 0 and 1)
5063
C. The probability that the image matches the corresponding label in our set of labels
5164
D. The accuracy of our model

responses/03-model.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
*Nailed it!*
2+
3+
Remember, the label arrays are only used to associate images with their lables.
4+
15
## Model Generation
26
Every NN is constructed from a series of connected layers that are full of connection nodes. Simple mathematical operations are undertaken at each node in each layer, yet through the volume of connections and operations, these ML models can perform impressive and complex tasks.
37

48
Our model will be constructed from 3 layers. The first layer – often referred to as the Input Layer – will intake an image and format the data structure in a method acceptable for the subsequent layers. In our case, this first layer will be a Flatten layer that intakes a multi-dimensional array and produces an array of a single dimension, this places all the pixel data on an equal depth during input. Both of the next layers will be simple fully connected layers, referred to as Dense layers, with 128 and 10 nodes respectively. These fully connected layers are the simplest layer in the sense of understanding, yet allow for the greatest number of layer-to-layer connections and relationships.
59

610
The final bit of hyper-technical knowledge you'll need to learn is that each layer can have its own particular mathematical operation. These activation functions determine the form and relationship between the information provided by the layer. The first dense layer will feature a Rectified Linear Unit (ReLU) Activation Function that outputs values between zero and 1; mathematically, the activation function behaves like f(x)=max(0,x). The final layer uses the softmax activation function. This function also produces values in the 0-1 range, BUT generates these values such that the sum of the outputs will be 1! This makes the softmax a layer that is excellent at outputting probabilities.
11+
712
```console
813
>>> model = keras.Sequential([ keras.layers.Flatten(input_shape=(28,28)), keras.layers.Dense(128, activation=tf.nn.relu), keras.layers.Dense(10, activation=tf.nn.softmax)])
914

0 commit comments

Comments
 (0)