{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Solutions" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ ":\n", "# Activation (sigmoid) function\n", "def sigmoid(x):\n", " return 1 / (1 + np.exp(-x))\n", "\n", "def output_formula(features, weights, bias):\n", " return sigmoid(np.dot(features, weights) + bias)\n", "\n", "def error_formula(y, output):\n", " return - y*np.log(output) - (1 - y) * np.log(1-output)\n", "\n", "def update_weights(x, y, weights, bias, learnrate):\n", " output = output_formula(x, weights, bias)\n", " d_error = y - output\n", " weights += learnrate * d_error * x\n", " bias += learnrate * d_error\n", " return weights, bias" ] } ], "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 }