diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index efead2d0..00000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,57 +0,0 @@ -name: Build Documentation using MkDocs - -# Controls when the action will run. Triggers the workflow on push or pull request -# events but only for the master branch -on: - push: - branches: [master] - pull_request: - branches: [master] - -env: - GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} - -permissions: - contents: 'write' - id-token: 'write' - pull-requests: 'write' -jobs: - build: - name: Build and Deploy Documentation - runs-on: ubuntu-latest - - steps: - - name: Checkout Branch - uses: actions/checkout@v3 - if: github.event_name == 'pull_request' - with: - fetch-depth: 0 - ref: ${{ github.event.pull_request.head.ref }} - persist-credentials: false - - - name: Checkout Master - uses: actions/checkout@v3 - - if: github.event_name == 'push' - with: - fetch-depth: 0 - persist-credentials: false - - - name: Set up Python 3.7 - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install mkdocs-material - - - name: Check - run: | - pwd - ls -la - - name: Deploy - run: | - git pull - mkdocs gh-deploy diff --git a/.gitignore b/.gitignore deleted file mode 100644 index b7fb052b..00000000 --- a/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -site/ -.DS_Store -~$* diff --git a/.ipynb_checkpoints/Untitled-checkpoint.ipynb b/.ipynb_checkpoints/Untitled-checkpoint.ipynb deleted file mode 100644 index 7fec5150..00000000 --- a/.ipynb_checkpoints/Untitled-checkpoint.ipynb +++ /dev/null @@ -1,6 +0,0 @@ -{ - "cells": [], - "metadata": {}, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/.ipynb_checkpoints/Untitled1-checkpoint.ipynb b/.ipynb_checkpoints/Untitled1-checkpoint.ipynb deleted file mode 100644 index 7fec5150..00000000 --- a/.ipynb_checkpoints/Untitled1-checkpoint.ipynb +++ /dev/null @@ -1,6 +0,0 @@ -{ - "cells": [], - "metadata": {}, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/.ipynb_checkpoints/Untitled2-checkpoint.ipynb b/.ipynb_checkpoints/Untitled2-checkpoint.ipynb deleted file mode 100644 index 7fec5150..00000000 --- a/.ipynb_checkpoints/Untitled2-checkpoint.ipynb +++ /dev/null @@ -1,6 +0,0 @@ -{ - "cells": [], - "metadata": {}, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/src/ops/01-intro.md b/.nojekyll similarity index 100% rename from src/ops/01-intro.md rename to .nojekyll diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 9a49861c..00000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "cSpell.words": [ - "Mojhave", - "Trinkit", - "coderdojo", - "jupyter", - "randint" - ] -} \ No newline at end of file diff --git a/404.html b/404.html new file mode 100644 index 00000000..90935e13 --- /dev/null +++ b/404.html @@ -0,0 +1,1864 @@ + + + +
+ + + + + + + + + + + + + + + + + + +Here are some suggested programs for doing more advanced Python programming. Here we define advanced as anything that is not covered under our Beginning Python class that usually runs between one and three hours.
+This lab uses the random number function to generate dice rolls. It uses a while loop to continue to roll a pair of six-sided dice repeatedly. +[./02-roll-the-dice.md]
+ + + + + + + + + + + + + + + +In this game the program generates two random numbers between 1 and 6. The program then asks the user if they want to roll the dice again. If they answer y or yes then the pair of +dice are rolled again.
+import random
+min = 1
+max = 6
+
+roll_again = "yes"
+
+while roll_again == "yes" or roll_again == "y":
+ print("Rolling the dice. The values are:")
+ print(random.randint(min, max))
+ print(random.randint(min, max))
+ roll_again = input("Roll the dices again?")
+
Rolling the dice. The values are:
+4
+4
+Roll the dices again?
+
\n | MMM_close | \nMMM_volume | \nMMM_high | \nMMM_low | \nDE_close | \nDE_volume | \nDE_high | \nDE_low | \nMDT_close | \nMDT_volume | \n... | \nTSLA_high | \nTSLA_low | \nAMZN_close | \nAMZN_volume | \nAMZN_high | \nAMZN_low | \nGOOG_close | \nGOOG_volume | \nGOOG_high | \nGOOG_low | \n
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2018-01-02 | \n235.639999 | \n2931000 | \n237.070007 | \n232.809998 | \n158.009995 | \n1897600 | \n158.059998 | \n156.550003 | \n82.209999 | \n4783500 | \n... | \n322.109985 | \n311.000000 | \n1189.010010 | \n2694500 | \n1190.000000 | \n1170.510010 | \n1065.000000 | \n1237600 | \n1066.939941 | \n1045.229980 | \n
2018-01-03 | \n235.630005 | \n2193700 | \n235.729996 | \n233.289993 | \n158.729996 | \n1392300 | \n159.100006 | \n157.639999 | \n83.919998 | \n6879100 | \n... | \n325.250000 | \n315.549988 | \n1204.199951 | \n3108800 | \n1205.489990 | \n1188.300049 | \n1082.479980 | \n1430200 | \n1086.290039 | \n1063.209961 | \n
2018-01-04 | \n238.710007 | \n2243100 | \n239.440002 | \n236.470001 | \n159.639999 | \n1747000 | \n160.100006 | \n157.350006 | \n84.120003 | \n5943200 | \n... | \n318.549988 | \n305.679993 | \n1209.589966 | \n3022100 | \n1215.869995 | \n1204.660034 | \n1086.400024 | \n1004600 | \n1093.569946 | \n1084.001953 | \n
2018-01-05 | \n240.570007 | \n1835900 | \n240.899994 | \n237.740005 | \n160.320007 | \n1574400 | \n160.470001 | \n156.589996 | \n85.540001 | \n7428500 | \n... | \n317.239990 | \n312.000000 | \n1229.140015 | \n3544700 | \n1229.140015 | \n1210.000000 | \n1102.229980 | \n1279100 | \n1104.250000 | \n1092.000000 | \n
2018-01-08 | \n239.789993 | \n1869000 | \n240.940002 | \n239.179993 | \n161.110001 | \n2711800 | \n161.179993 | \n158.899994 | \n85.510002 | \n6117600 | \n... | \n337.019989 | \n315.500000 | \n1246.869995 | \n4279500 | \n1253.079956 | \n1232.030029 | \n1106.939941 | \n1047600 | \n1111.270020 | \n1101.619995 | \n
5 rows × 52 columns
\n\n | index | \nMMM_close | \nMMM_volume | \nMMM_high | \nMMM_low | \nDE_close | \nDE_volume | \nDE_high | \nDE_low | \nMDT_close | \n... | \n50DayMA_AMZN | \n100DayMA_AMZN | \n200DayMA_AMZN | \n5DayMA_GOOG | \n10DayMA_GOOG | \n20DayMA_GOOG | \n50DayMA_GOOG | \n100DayMA_GOOG | \n200DayMA_GOOG | \nnumericalIndex | \n
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n2018-10-16 | \n202.330002 | \n1939500 | \n202.520004 | \n199.229996 | \n151.960007 | \n2124500 | \n152.320007 | \n148.210007 | \n96.550003 | \n... | \n1920.197803 | \n1829.428901 | \n1648.138599 | \n1096.829980 | \n1130.042969 | \n1157.325983 | \n1186.640586 | \n1173.449993 | \n1128.366644 | \n0 | \n
1 | \n2018-10-17 | \n202.929993 | \n1824200 | \n203.770004 | \n200.449997 | \n151.639999 | \n1516000 | \n152.479996 | \n149.429993 | \n97.290001 | \n... | \n1919.582803 | \n1831.644701 | \n1651.352199 | \n1103.723975 | \n1121.316968 | \n1154.555981 | \n1184.109985 | \n1173.850292 | \n1128.620094 | \n1 | \n
2 | \n2018-10-18 | \n200.380005 | \n2339400 | \n202.520004 | \n198.399994 | \n147.199997 | \n2491800 | \n151.059998 | \n145.710007 | \n95.919998 | \n... | \n1917.266802 | \n1833.223201 | \n1654.184799 | \n1105.453979 | \n1113.294971 | \n1149.610980 | \n1180.957185 | \n1174.126792 | \n1128.647544 | \n2 | \n
3 | \n2018-10-19 | \n199.850006 | \n3167300 | \n201.100006 | \n198.369995 | \n145.910004 | \n1901500 | \n149.000000 | \n145.369995 | \n93.940002 | \n... | \n1914.577002 | \n1834.614601 | \n1656.957000 | \n1102.729980 | \n1107.205969 | \n1146.129480 | \n1177.904385 | \n1174.413391 | \n1128.697843 | \n3 | \n
4 | \n2018-10-22 | \n201.360001 | \n3263300 | \n203.399994 | \n199.690002 | \n145.440002 | \n1702300 | \n146.949997 | \n144.330002 | \n93.620003 | \n... | \n1912.637002 | \n1836.211401 | \n1659.757800 | \n1104.511987 | \n1102.424976 | \n1142.518982 | \n1175.175386 | \n1174.575092 | \n1128.692494 | \n4 | \n
5 rows × 132 columns
\nWe will program and train a machine learning model to recognize handwritten numbers. The code for this lesson can be found here.
+Process of determining the function that gives a plausible result y for a set of inputs, in form of a vector x. In its simplest form, this could be linear regression, where we find the line of best fit through the data.
+In more complex forms, however, this can be training a neural network to fit very non-linear data. We will use a type of neural network to recognize our handwritten numbers.
+As you can see, there are many different types, or architectures of neural networks. Some of the most common are Feed Forward, Recurrent, LSTM, and AutoEncoder neural networks. The other most common is the one that we will use, or a Convolutional Neural Network.
+Since we have image data, we will use a Convolutional Neural Network (CNN). A CNN works by sliding "windows" over the input image and aggregating nearby pixels together.
+
For this project, we will be using a machine learning package called Keras. This makes it really easy to construct our neural network. We also import matplotlib to visualize our data, and numpy for some utilities. +
import keras
+from keras.datasets import mnist # Get dataset
+from keras.models import Sequential
+from keras.layers import Dense, Dropout, Flatten # Need these types of layers
+from keras.layers import Conv2D, MaxPooling2D # Need convolutional layers
+
+import matplotlib.pyplot as plt
+import matplotlib.image as mpimg
+
+import numpy as np
+
Important to load both a training and testing set to make sure the CNN is not "memorizing" the set of images it will train on. This would lead to awful accuracy in the "real world" +
# input image dimensions (pixels)
+img_rows, img_cols = 28, 28
+
+# the data, split between train and test sets
+(x_train, y_train), (x_test, y_test) = mnist.load_data()
+
+# manipulate the data for the CNN
+x_train = x_train.reshape(x_train.shape[0], img_rows, img_cols, 1)
+x_test = x_test.reshape(x_test.shape[0], img_rows, img_cols, 1)
+input_shape = (img_rows, img_cols, 1)
+
We want to have our CNN work with numbers between 0 and 1. Since pixel values are from 0-255, we divide all numbers by 255 in order to make them between 0 and 1. We then can see how many training and testing samples we have. +
x_train = x_train.astype('float32')
+x_test = x_test.astype('float32')
+x_train /= 255
+x_test /= 255
+print('x_train shape:', x_train.shape)
+print(x_train.shape[0], 'train samples')
+print(x_test.shape[0], 'test samples')
+
In the next few cells, we will look at an example of a digit and see what number it is in the training set.
+x_train[0]
+
pixels = x_train[0].reshape((28, 28))
+
+plt.imshow(pixels, cmap='gray')
+
print(y_train[0])
+
We want to convert the desired output from a number n to a vector where the nth element is 1 and the rest are 0.
+Example: n = 5 Resulting Vector = {0, 0, 0, 0, 0, 1, 0, 0, 0, 0}
+num_classes = 10
+
+y_train = keras.utils.to_categorical(y_train, num_classes)
+y_test = keras.utils.to_categorical(y_test, num_classes)
+
Now here is the fun part. Building the model! We will have a 5 layer neural network. Feel free to play around with some of the parameters and see what works better or worse!
+model = Sequential()
+model.add(Conv2D(32, kernel_size=(3, 3),
+ activation='relu',
+ input_shape=input_shape))
+model.add(Conv2D(64, (3, 3), activation='relu'))
+model.add(MaxPooling2D(pool_size=(2, 2)))
+model.add(Dropout(0.25)) # Prevent overfitting
+model.add(Flatten())
+model.add(Dense(128, activation='relu'))
+model.add(Dropout(0.5))
+model.add(Dense(num_classes, activation='softmax'))
+
+model.summary()
+
Here, we will set two parameters for the network. The first is batch size, which determines how many training examples we will look at before changing the weights in the model. We will also set the number of epochs, or iterations through the entire training set.
+batch_size = 128 # How many training examples will we look at before updating the weights in the matrix
+epochs = 12 # How many times we will run through the complete training set
+
Here, we compile the model and then train it. A couple things to note. We are using the Adam optimizer, as compared to others such as stochastic gradient descent. We are measuring the success of the model through the categorical crossentropy loss metric, which determines how to adjust the weights within the model.
+model.compile(loss=keras.losses.categorical_crossentropy,
+ optimizer=keras.optimizers.Adam(),
+ metrics=['accuracy'])
+
+model.fit(x_train, y_train,
+ batch_size=batch_size,
+ epochs=epochs,
+ verbose=1,
+ validation_data=(x_test, y_test))
+
Now here is the big finish, lets see how well the model performs! We will do this by running through our test set and having the model produce a prediction. Thankfully, there is already a function built into the model for this. +
score = model.evaluate(x_test, y_test, verbose=0)
+print('Test loss:', score[0])
+print('Test accuracy:', score[1])
+
Let's see what happens on an individual image level: +
to_predict = np.array([x_test[0]])
+
+output = model.predict(to_predict)
+
+pixels = to_predict[0].reshape((28, 28))
+
+plt.imshow(pixels, cmap='gray')
+
output
+
np.argmax(output)
+