From 3011a24656ca853ab6f75f550689fa062452339e Mon Sep 17 00:00:00 2001 From: Varad Bhatnagar Date: Wed, 24 Oct 2018 14:02:34 +0530 Subject: [PATCH 1/7] Update Neural_Network.ipynb --- Neural_Network.ipynb | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/Neural_Network.ipynb b/Neural_Network.ipynb index 7449d0a..4beeb2b 100644 --- a/Neural_Network.ipynb +++ b/Neural_Network.ipynb @@ -59,27 +59,17 @@ " output_layer_input1=np.dot(hiddenlayer_activations,wout)\n", " output_layer_input= output_layer_input1+ bout\n", " output = sigmoid(output_layer_input)" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ "#Backpropagation\n", - "E = y-output\n", - "slope_output_layer = derivatives_sigmoid(output)\n", - "slope_hidden_layer = derivatives_sigmoid(hiddenlayer_activations)\n", - "d_output = E * slope_output_layer\n", - "Error_at_hidden_layer = d_output.dot(wout.T)\n", - "d_hiddenlayer = Error_at_hidden_layer * slope_hidden_layer\n", - "wout += hiddenlayer_activations.T.dot(d_output) *lr\n", - "bout += np.sum(d_output, axis=0,keepdims=True) *lr\n", - "wh += X.T.dot(d_hiddenlayer) *lr\n", - "bh += np.sum(d_hiddenlayer, axis=0,keepdims=True) *lr" + " E = y-output\n", + " slope_output_layer = derivatives_sigmoid(output)\n", + " slope_hidden_layer = derivatives_sigmoid(hiddenlayer_activations)\n", + " d_output = E * slope_output_layer\n", + " Error_at_hidden_layer = d_output.dot(wout.T)\n", + " d_hiddenlayer = Error_at_hidden_layer * slope_hidden_layer\n", + " wout += hiddenlayer_activations.T.dot(d_output) *lr\n", + " bout += np.sum(d_output, axis=0,keepdims=True) *lr\n", + " wh += X.T.dot(d_hiddenlayer) *lr\n", + " bh += np.sum(d_hiddenlayer, axis=0,keepdims=True) *lr" ] }, { From 3336b2c1755f4464138d7e2873550e65c0aa21ba Mon Sep 17 00:00:00 2001 From: Varad Bhatnagar Date: Wed, 24 Oct 2018 14:07:03 +0530 Subject: [PATCH 2/7] Delete Neural_Network.ipynb --- Neural_Network.ipynb | 134 ------------------------------------------- 1 file changed, 134 deletions(-) delete mode 100644 Neural_Network.ipynb diff --git a/Neural_Network.ipynb b/Neural_Network.ipynb deleted file mode 100644 index 4beeb2b..0000000 --- a/Neural_Network.ipynb +++ /dev/null @@ -1,134 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "(3, 4)\n" - ] - } - ], - "source": [ - "#Source code for Artificial Neural Network using python\n", - "import numpy as np\n", - "#Input array\n", - "X=np.array([[1,0,1,0],[1,0,1,1],[0,1,0,1]])\n", - "#Output\n", - "y=np.array([[1],[1],[0]])\n", - "\n", - "#Sigmoid Function\n", - "def sigmoid (x):\n", - " return 1/(1 + np.exp(-x))\n", - "\n", - "#Derivative of Sigmoid Function\n", - "def derivatives_sigmoid(x):\n", - " return x * (1 - x)\n", - "\n", - "#Variable initialization\n", - "epoch=5000 #Setting training iterations\n", - "lr=0.1 #Setting learning rate\n", - "inputlayer_neurons = X.shape[1] #number of features in data set\n", - "hiddenlayer_neurons = 3 #number of hidden layers neurons\n", - "output_neurons = 1 #number of neurons at output layer\n", - "\n", - "#weight and bias initialization\n", - "wh=np.random.uniform(size=(inputlayer_neurons,hiddenlayer_neurons))\n", - "bh=np.random.uniform(size=(1,hiddenlayer_neurons))\n", - "wout=np.random.uniform(size=(hiddenlayer_neurons,output_neurons))\n", - "bout=np.random.uniform(size=(1,output_neurons))" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "for i in range(epoch):\n", - "#Forward Propogation\n", - " hidden_layer_input1=np.dot(X,wh)\n", - " hidden_layer_input=hidden_layer_input1 + bh\n", - " hiddenlayer_activations = sigmoid(hidden_layer_input)\n", - " output_layer_input1=np.dot(hiddenlayer_activations,wout)\n", - " output_layer_input= output_layer_input1+ bout\n", - " output = sigmoid(output_layer_input)" - "#Backpropagation\n", - " E = y-output\n", - " slope_output_layer = derivatives_sigmoid(output)\n", - " slope_hidden_layer = derivatives_sigmoid(hiddenlayer_activations)\n", - " d_output = E * slope_output_layer\n", - " Error_at_hidden_layer = d_output.dot(wout.T)\n", - " d_hiddenlayer = Error_at_hidden_layer * slope_hidden_layer\n", - " wout += hiddenlayer_activations.T.dot(d_output) *lr\n", - " bout += np.sum(d_output, axis=0,keepdims=True) *lr\n", - " wh += X.T.dot(d_hiddenlayer) *lr\n", - " bh += np.sum(d_hiddenlayer, axis=0,keepdims=True) *lr" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[0.82938945]\n", - " [0.84310929]\n", - " [0.83800391]]\n" - ] - } - ], - "source": [ - "print (output)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [] - } - ], - "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 -} From 521ef6909a9ace11f9cee999984b1f88e2313db2 Mon Sep 17 00:00:00 2001 From: Varad Bhatnagar Date: Wed, 24 Oct 2018 14:07:40 +0530 Subject: [PATCH 3/7] Add files via upload --- Neural_Network.ipynb | 97 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Neural_Network.ipynb diff --git a/Neural_Network.ipynb b/Neural_Network.ipynb new file mode 100644 index 0000000..0bd97b1 --- /dev/null +++ b/Neural_Network.ipynb @@ -0,0 +1,97 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Source code for Artificial Neural Network using python\n", + "import numpy as np\n", + "#Input array\n", + "X=np.array([[1,0,1,0],[1,0,1,1],[0,1,0,1]])\n", + "#Output\n", + "y=np.array([[1],[1],[0]])\n", + "\n", + "#Sigmoid Function\n", + "def sigmoid (x):\n", + " return 1/(1 + np.exp(-x))\n", + "\n", + "#Derivative of Sigmoid Function\n", + "def derivatives_sigmoid(x):\n", + " return x * (1 - x)\n", + "\n", + "#Variable initialization\n", + "epoch=5000 #Setting training iterations\n", + "lr=0.1 #Setting learning rate\n", + "inputlayer_neurons = X.shape[1] #number of features in data set\n", + "hiddenlayer_neurons = 3 #number of hidden layers neurons\n", + "output_neurons = 1 #number of neurons at output layer\n", + "\n", + "#weight and bias initialization\n", + "wh=np.random.uniform(size=(inputlayer_neurons,hiddenlayer_neurons))\n", + "bh=np.random.uniform(size=(1,hiddenlayer_neurons))\n", + "wout=np.random.uniform(size=(hiddenlayer_neurons,output_neurons))\n", + "bout=np.random.uniform(size=(1,output_neurons))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "for i in range(epoch):\n", + "#Forward Propogation\n", + " hidden_layer_input1=np.dot(X,wh)\n", + " hidden_layer_input=hidden_layer_input1 + bh\n", + " hiddenlayer_activations = sigmoid(hidden_layer_input)\n", + " output_layer_input1=np.dot(hiddenlayer_activations,wout)\n", + " output_layer_input= output_layer_input1+ bout\n", + " output = sigmoid(output_layer_input)\n", + " \n", + "#Backpropagation\n", + " E = y-output\n", + " slope_output_layer = derivatives_sigmoid(output)\n", + " slope_hidden_layer = derivatives_sigmoid(hiddenlayer_activations)\n", + " d_output = E * slope_output_layer\n", + " Error_at_hidden_layer = d_output.dot(wout.T)\n", + " d_hiddenlayer = Error_at_hidden_layer * slope_hidden_layer\n", + " wout += hiddenlayer_activations.T.dot(d_output) *lr\n", + " bout += np.sum(d_output, axis=0,keepdims=True) *lr\n", + " wh += X.T.dot(d_hiddenlayer) *lr\n", + " bh += np.sum(d_hiddenlayer, axis=0,keepdims=True) *lr" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print (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.7.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 273e7ed1e5e9acd24e636f35c87f25c3f0e79125 Mon Sep 17 00:00:00 2001 From: Varad Bhatnagar Date: Wed, 24 Oct 2018 14:08:57 +0530 Subject: [PATCH 4/7] Update LinearRegression.r --- LinearRegression.r | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LinearRegression.r b/LinearRegression.r index 2d3c8f1..b43bf88 100644 --- a/LinearRegression.r +++ b/LinearRegression.r @@ -233,7 +233,7 @@ for(i in 1:10) trSize = 10 * i; trainingData <- head(dataS , trSize) - trmodel <- lm(y ~ x1 + x2 +x3 +x4 +x5 +x6 +x7 , data =dataS , x=T , y=T) + trmodel <- lm(y ~ x1 + x2 +x3 +x4 +x5 +x6 +x7 , data =trainingData , x=T , y=T) predictedY <- predict ( trmodel , trainingData) predictedY @@ -287,4 +287,4 @@ for(i in 1: 10) } plot(MSE) -lines(x = MSE , y= NULL , type ="l" , col="blue") \ No newline at end of file +lines(x = MSE , y= NULL , type ="l" , col="blue") From ff43aa6d1b5d73ab3110611da9020c9f46465cb3 Mon Sep 17 00:00:00 2001 From: Varad Bhatnagar Date: Wed, 24 Oct 2018 14:27:25 +0530 Subject: [PATCH 5/7] Update README.md --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index ee23961..7e1a522 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,5 @@ # MLA -Machine Learning and Algorithms Codes for BE IT. - - -Codes are contributed by Varad and Stony. +Machine Learning and Applications Codes SPPU BE IT 2015 Course `my_data.txt` is the dataset for Linear Regression. From 9ed3b001a51ad7d26b80883c9ba31659dab8a677 Mon Sep 17 00:00:00 2001 From: Varad Bhatnagar Date: Fri, 26 Oct 2018 01:12:05 +0530 Subject: [PATCH 6/7] Delete Neural_Network.ipynb --- Neural_Network.ipynb | 97 -------------------------------------------- 1 file changed, 97 deletions(-) delete mode 100644 Neural_Network.ipynb diff --git a/Neural_Network.ipynb b/Neural_Network.ipynb deleted file mode 100644 index 0bd97b1..0000000 --- a/Neural_Network.ipynb +++ /dev/null @@ -1,97 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#Source code for Artificial Neural Network using python\n", - "import numpy as np\n", - "#Input array\n", - "X=np.array([[1,0,1,0],[1,0,1,1],[0,1,0,1]])\n", - "#Output\n", - "y=np.array([[1],[1],[0]])\n", - "\n", - "#Sigmoid Function\n", - "def sigmoid (x):\n", - " return 1/(1 + np.exp(-x))\n", - "\n", - "#Derivative of Sigmoid Function\n", - "def derivatives_sigmoid(x):\n", - " return x * (1 - x)\n", - "\n", - "#Variable initialization\n", - "epoch=5000 #Setting training iterations\n", - "lr=0.1 #Setting learning rate\n", - "inputlayer_neurons = X.shape[1] #number of features in data set\n", - "hiddenlayer_neurons = 3 #number of hidden layers neurons\n", - "output_neurons = 1 #number of neurons at output layer\n", - "\n", - "#weight and bias initialization\n", - "wh=np.random.uniform(size=(inputlayer_neurons,hiddenlayer_neurons))\n", - "bh=np.random.uniform(size=(1,hiddenlayer_neurons))\n", - "wout=np.random.uniform(size=(hiddenlayer_neurons,output_neurons))\n", - "bout=np.random.uniform(size=(1,output_neurons))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "for i in range(epoch):\n", - "#Forward Propogation\n", - " hidden_layer_input1=np.dot(X,wh)\n", - " hidden_layer_input=hidden_layer_input1 + bh\n", - " hiddenlayer_activations = sigmoid(hidden_layer_input)\n", - " output_layer_input1=np.dot(hiddenlayer_activations,wout)\n", - " output_layer_input= output_layer_input1+ bout\n", - " output = sigmoid(output_layer_input)\n", - " \n", - "#Backpropagation\n", - " E = y-output\n", - " slope_output_layer = derivatives_sigmoid(output)\n", - " slope_hidden_layer = derivatives_sigmoid(hiddenlayer_activations)\n", - " d_output = E * slope_output_layer\n", - " Error_at_hidden_layer = d_output.dot(wout.T)\n", - " d_hiddenlayer = Error_at_hidden_layer * slope_hidden_layer\n", - " wout += hiddenlayer_activations.T.dot(d_output) *lr\n", - " bout += np.sum(d_output, axis=0,keepdims=True) *lr\n", - " wh += X.T.dot(d_hiddenlayer) *lr\n", - " bh += np.sum(d_hiddenlayer, axis=0,keepdims=True) *lr" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print (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.7.0" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} From 0b00c36d788caba45b2335d82fc1f78db95b0b38 Mon Sep 17 00:00:00 2001 From: Varad Bhatnagar Date: Fri, 26 Oct 2018 01:12:47 +0530 Subject: [PATCH 7/7] Add files via upload Corrected Derivative of Sigmoid function --- Neural_Network.ipynb | 109 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Neural_Network.ipynb diff --git a/Neural_Network.ipynb b/Neural_Network.ipynb new file mode 100644 index 0000000..ffe3081 --- /dev/null +++ b/Neural_Network.ipynb @@ -0,0 +1,109 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#Source code for Artificial Neural Network using python\n", + "import numpy as np\n", + "#Input array\n", + "X=np.array([[1,0,1,0],[1,0,1,1],[0,1,0,1]])\n", + "#Output\n", + "y=np.array([[1],[1],[0]])\n", + "\n", + "#Sigmoid Function\n", + "def sigmoid (x):\n", + " return 1/(1 + np.exp(-x))\n", + "\n", + "#Derivative of Sigmoid Function\n", + "def derivatives_sigmoid(x):\n", + " return sigmoid(x) * (1 - sigmoid(x))\n", + "\n", + "#Variable initialization\n", + "epoch=5000 #Setting training iterations\n", + "lr=0.1 #Setting learning rate\n", + "inputlayer_neurons = X.shape[1] #number of features in data set\n", + "hiddenlayer_neurons = 3 #number of hidden layers neurons\n", + "output_neurons = 1 #number of neurons at output layer\n", + "\n", + "#weight and bias initialization\n", + "wh=np.random.uniform(size=(inputlayer_neurons,hiddenlayer_neurons))\n", + "bh=np.random.uniform(size=(1,hiddenlayer_neurons))\n", + "wout=np.random.uniform(size=(hiddenlayer_neurons,output_neurons))\n", + "bout=np.random.uniform(size=(1,output_neurons))" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "for i in range(epoch):\n", + "#Forward Propogation\n", + " hidden_layer_input1=np.dot(X,wh)\n", + " hidden_layer_input=hidden_layer_input1 + bh\n", + " hiddenlayer_activations = sigmoid(hidden_layer_input)\n", + " output_layer_input1=np.dot(hiddenlayer_activations,wout)\n", + " output_layer_input= output_layer_input1+ bout\n", + " output = sigmoid(output_layer_input)\n", + " \n", + "#Backpropagation\n", + " E = y-output\n", + " slope_output_layer = derivatives_sigmoid(output)\n", + " slope_hidden_layer = derivatives_sigmoid(hiddenlayer_activations)\n", + " d_output = E * slope_output_layer\n", + " Error_at_hidden_layer = d_output.dot(wout.T)\n", + " d_hiddenlayer = Error_at_hidden_layer * slope_hidden_layer\n", + " wout += hiddenlayer_activations.T.dot(d_output) *lr\n", + " bout += np.sum(d_output, axis=0,keepdims=True) *lr\n", + " wh += X.T.dot(d_hiddenlayer) *lr\n", + " bh += np.sum(d_hiddenlayer, axis=0,keepdims=True) *lr" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[0.9980349 ]\n", + " [0.99553424]\n", + " [0.00723341]]\n" + ] + } + ], + "source": [ + "\n", + "print (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.7.0" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}