From 7953bbed84821c007d8f0ce560354c0517356c36 Mon Sep 17 00:00:00 2001 From: Brian Ross Date: Thu, 14 May 2020 11:43:54 -0400 Subject: [PATCH 1/2] Update import statement - [x] Fixes broken import statement - [x] Fixes #109 for now including data dictionary at end of assignment --- .../LS_DS_423_Keras_Assignment.ipynb | 260 ++++++++++-------- 1 file changed, 142 insertions(+), 118 deletions(-) diff --git a/module3-Intro-to-Keras/LS_DS_423_Keras_Assignment.ipynb b/module3-Intro-to-Keras/LS_DS_423_Keras_Assignment.ipynb index 4566e560..9ed2ee24 100644 --- a/module3-Intro-to-Keras/LS_DS_423_Keras_Assignment.ipynb +++ b/module3-Intro-to-Keras/LS_DS_423_Keras_Assignment.ipynb @@ -1,120 +1,144 @@ { - "cells": [ - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "pBQsZEJmubLs" - }, - "source": [ - "\n", - "

\n", - "\n", - "# Neural Network Framework (Keras)\n", - "\n", - "## *Data Science Unit 4 Sprint 2 Assignment 3*\n", - "\n", - "## Use the Keras Library to build a Multi-Layer Perceptron Model on the Boston Housing dataset\n", - "\n", - "- The Boston Housing dataset comes with the Keras library so use Keras to import it into your notebook. \n", - "- Normalize the data (all features should have roughly the same scale)\n", - "- Import the type of model and layers that you will need from Keras.\n", - "- Instantiate a model object and use `model.add()` to add layers to your model\n", - "- Since this is a regression model you will have a single output node in the final layer.\n", - "- Use activation functions that are appropriate for this task\n", - "- Compile your model\n", - "- Fit your model and report its accuracy in terms of Mean Squared Error\n", - "- Use the history object that is returned from model.fit to make graphs of the model's loss or train/validation accuracies by epoch. \n", - "- Run this same data through a linear regression model. Which achieves higher accuracy?\n", - "- Do a little bit of feature engineering and see how that affects your neural network model. (you will need to change your model to accept more inputs)\n", - "- After feature engineering, which model sees a greater accuracy boost due to the new features?" - ] + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "LS_DS_433_Keras_Assignment.ipynb", + "provenance": [] + }, + "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" + } }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "8NLTAR87uYJ-" - }, - "outputs": [], - "source": [ - "##### Your Code Here #####\n", - "\n", - "from tensorflow.keras.datasets import Boston" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "SfcFnOONyuNm" - }, - "source": [ - "## Use the Keras Library to build an image recognition network using the Fashion-MNIST dataset (also comes with keras)\n", - "\n", - "- Load and preprocess the image data similar to how we preprocessed the MNIST data in class.\n", - "- Make sure to one-hot encode your category labels\n", - "- The number of nodes in your output layer should equal the number of classes you want to predict for Fashion-MNIST.\n", - "- Try different hyperparameters. What is the highest accuracy that you are able to achieve.\n", - "- Use the history object that is returned from model.fit to make graphs of the model's loss or train/validation accuracies by epoch. \n", - "- Remember that neural networks fall prey to randomness so you may need to run your model multiple times (or use Cross Validation) in order to tell if a change to a hyperparameter is truly producing better results." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "colab": {}, - "colab_type": "code", - "id": "szi6-IpuzaH1" - }, - "outputs": [], - "source": [ - "##### Your Code Here #####" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "colab_type": "text", - "id": "zv_3xNMjzdLI" - }, - "source": [ - "## Stretch Goals:\n", - "\n", - "- Use Hyperparameter Tuning to make the accuracy of your models as high as possible. (error as low as possible)\n", - "- Use Cross Validation techniques to get more consistent results with your model.\n", - "- Use GridSearchCV to try different combinations of hyperparameters. \n", - "- Start looking into other types of Keras layers for CNNs and RNNs maybe try and build a CNN model for fashion-MNIST to see how the results compare." - ] - } - ], - "metadata": { - "colab": { - "name": "LS_DS_433_Keras_Assignment.ipynb", - "provenance": [], - "version": "0.3.2" - }, - "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": 4 -} + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "pBQsZEJmubLs" + }, + "source": [ + "\n", + "

\n", + "\n", + "# Neural Network Framework (Keras)\n", + "\n", + "## *Data Science Unit 4 Sprint 2 Assignment 3*\n", + "\n", + "## Use the Keras Library to build a Multi-Layer Perceptron Model on the Boston Housing dataset\n", + "\n", + "- The Boston Housing dataset comes with the Keras library so use Keras to import it into your notebook. \n", + "- Normalize the data (all features should have roughly the same scale)\n", + "- Import the type of model and layers that you will need from Keras.\n", + "- Instantiate a model object and use `model.add()` to add layers to your model\n", + "- Since this is a regression model you will have a single output node in the final layer.\n", + "- Use activation functions that are appropriate for this task\n", + "- Compile your model\n", + "- Fit your model and report its accuracy in terms of Mean Squared Error\n", + "- Use the history object that is returned from model.fit to make graphs of the model's loss or train/validation accuracies by epoch. \n", + "- Run this same data through a linear regression model. Which achieves higher accuracy?\n", + "- Do a little bit of feature engineering and see how that affects your neural network model. (you will need to change your model to accept more inputs, a data dictionary is included at the bottom of the assignment)\n", + "- After feature engineering, which model sees a greater accuracy boost due to the new features?" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab_type": "code", + "id": "8NLTAR87uYJ-", + "colab": {} + }, + "source": [ + "from tensorflow.keras.datasets import load_boston\n", + "\n", + "### YOUR CODE HERE ###" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "SfcFnOONyuNm" + }, + "source": [ + "## Use the Keras Library to build an image recognition network using the Fashion-MNIST dataset (also comes with keras)\n", + "\n", + "- Load and preprocess the image data similar to how we preprocessed the MNIST data in class.\n", + "- Make sure to one-hot encode your category labels\n", + "- The number of nodes in your output layer should equal the number of classes you want to predict for Fashion-MNIST.\n", + "- Try different hyperparameters. What is the highest accuracy that you are able to achieve.\n", + "- Use the history object that is returned from model.fit to make graphs of the model's loss or train/validation accuracies by epoch. \n", + "- Remember that neural networks fall prey to randomness so you may need to run your model multiple times (or use Cross Validation) in order to tell if a change to a hyperparameter is truly producing better results." + ] + }, + { + "cell_type": "code", + "metadata": { + "colab_type": "code", + "id": "szi6-IpuzaH1", + "colab": {} + }, + "source": [ + "##### Your Code Here #####" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "zv_3xNMjzdLI" + }, + "source": [ + "## Stretch Goals:\n", + "\n", + "- Use Hyperparameter Tuning to make the accuracy of your models as high as possible. (error as low as possible)\n", + "- Use Cross Validation techniques to get more consistent results with your model.\n", + "- Use GridSearchCV to try different combinations of hyperparameters. \n", + "- Start looking into other types of Keras layers for CNNs and RNNs maybe try and build a CNN model for fashion-MNIST to see how the results compare." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "PM7f7KXi2FPg", + "colab_type": "text" + }, + "source": [ + "```Python\n", + " CRIM per capita crime rate by town\n", + " ZN proportion of residential land zoned for lots over 25,000 sq.ft.\n", + " INDUS proportion of non-retail business acres per town\n", + " CHAS Charles River dummy variable (= 1 if tract bounds river; 0 otherwise)\n", + " NOX nitric oxides concentration (parts per 10 million)\n", + " RM average number of rooms per dwelling\n", + " AGE proportion of owner-occupied units built prior to 1940\n", + " DIS weighted distances to five Boston employment centres\n", + " RAD index of accessibility to radial highways\n", + " TAX full-value property-tax rate per $10,000\n", + " PTRATIO pupil-teacher ratio by town\n", + " B 1000(Bk - 0.63)^2 where Bk is the proportion of blacks by town\n", + " LSTAT % lower status of the population\n", + " MEDV Median value of owner-occupied homes in $1000's\n", + " ```" + ] + } + ] +} \ No newline at end of file From 031ada27a68ed048dd684a63b59f7f4a6e86add6 Mon Sep 17 00:00:00 2001 From: Brian Ross Date: Thu, 14 May 2020 22:39:19 -0400 Subject: [PATCH 2/2] Update --- .../LS_DS_423_Keras_Assignment.ipynb | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/module3-Intro-to-Keras/LS_DS_423_Keras_Assignment.ipynb b/module3-Intro-to-Keras/LS_DS_423_Keras_Assignment.ipynb index 9ed2ee24..5f3e51dc 100644 --- a/module3-Intro-to-Keras/LS_DS_423_Keras_Assignment.ipynb +++ b/module3-Intro-to-Keras/LS_DS_423_Keras_Assignment.ipynb @@ -60,15 +60,43 @@ "metadata": { "colab_type": "code", "id": "8NLTAR87uYJ-", - "colab": {} + "colab": { + "base_uri": "https://localhost:8080/", + "height": 204 + }, + "outputId": "0c5c3f19-cb63-435f-ce29-e2380de67463" }, "source": [ - "from tensorflow.keras.datasets import load_boston\n", + "from tensorflow.keras.datasets import boston_housing\n", + "\n", "\n", - "### YOUR CODE HERE ###" + "dir(boston_housing)" ], - "execution_count": 0, - "outputs": [] + "execution_count": 5, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['__builtins__',\n", + " '__cached__',\n", + " '__doc__',\n", + " '__file__',\n", + " '__loader__',\n", + " '__name__',\n", + " '__package__',\n", + " '__path__',\n", + " '__spec__',\n", + " '_sys',\n", + " 'load_data']" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 5 + } + ] }, { "cell_type": "markdown",