{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Solutions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### One-hot encoding the rank" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Make dummy variables for rank\n", "one_hot_data = pd.concat([data, pd.get_dummies(data['rank'], prefix='rank')], axis=1)\n", "\n", "# Drop the previous rank column\n", "one_hot_data = one_hot_data.drop('rank', axis=1)\n", "\n", "# Print the first 10 rows of our data\n", "one_hot_data[:10]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Scaling the data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Copying our data\n", "processed_data = one_hot_data[:]\n", "\n", "# Scaling the columns\n", "processed_data['gre'] = processed_data['gre']/800\n", "processed_data['gpa'] = processed_data['gpa']/4.0\n", "processed_data[:10]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Backpropagating the data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "def error_term_formula(x, y, output):\n", " return (y - output)*sigmoid_prime(x)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "## alternative solution ##\n", "# you could also *only* use y and the output \n", "# and calculate sigmoid_prime directly from the activated output!\n", "\n", "# below is an equally valid solution (it doesn't utilize x)\n", "def error_term_formula(x, y, output):\n", " return (y-output) * output * (1 - output)" ] } ], "metadata": { "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.6.3" } }, "nbformat": 4, "nbformat_minor": 2 }