From 347da0af170cedef8abbdce5b268e06c677e57b3 Mon Sep 17 00:00:00 2001 From: proflamyt <53262578+proflamyt@users.noreply.github.com> Date: Fri, 17 Apr 2020 08:38:20 +0000 Subject: [PATCH 1/4] Add files via upload --- olawale_abdulrasheed_olamide-master.zip | Bin 0 -> 2337 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 olawale_abdulrasheed_olamide-master.zip diff --git a/olawale_abdulrasheed_olamide-master.zip b/olawale_abdulrasheed_olamide-master.zip new file mode 100644 index 0000000000000000000000000000000000000000..bc7d29e2530d2115971b520090f5831de9376833 GIT binary patch literal 2337 zcmb7_c{mjKAIE3h=Z28vNRD-c!DL2}D|Z;yI3m+rGOkH8XcsAMB{>H}D?+4$7ByS$ z!MJB!g~3ka93x4{U0JpLcAwv|&(rVweV)(reZGIZKA(R+?-$I8mrn%n`K(_{gME2? zEouN^06qj6g$%(WkSI(<$ay3o5R1hic0WUL7_4q6l0d|s*N1!X1Ay`Ga{OUmQ9@r( z70N~%bRGcU7k&Uh_Zv~}HkK!xZS+Dhe=$QnEK_cSB*8-g$r5M`RR}{`9P`< zdhfIPyPfktgvx37%ovKbojwgey#`6l$G@4$+pgT8)g&Y>di$|784_0}ZzbTS>Dsr# z^z@&~-eGaBYE1Z%VE!k1A?j`JQoTNHvh3S$@p=L^oe9~(IVMs%uUK`Mpa;MYF7q%h!myu^)k{`AJnm?6zb6TOKfD!2(=!-7pGp`K|>_cD8 z#b@s;F{v7UyxByN`>5$s9Oi%b08ZO_kn!HU$d}YF4(pmwStD{~ZmQNtI3o<!mUj`_;Gl6Y3(_b5#xla!g+cpGEV*VMisoT$$AnB8nLsvb1nfgWe+I%jQ4c})w%D(yubffRU8mnof?@dAp!{CH*X2xk~Ab(SVEk?SKr-m&oO^a#hS-Z9(m zTts-Tu<`hHd}u^}4^4h)YDo7UT}7El$CpGJmGHMZfgz{v%uC&*% zU~{^l2VfB~;R^J!s*uD#sYz0m8QmrubU7k}%mX zEMeQe+%+{x_c%PQ{Ori-^z6w$hu$K>oHq2?7mQ9vt=$@s$N>d4*!`fG?{A)kCM4m7)`%t!! zv|sOdj$cucOse_Ke6qPc&(q20>?*`j%9>Qy=-84akHUxN?N%*^TI_6e4}`h>XuG!G zfJbKRKq+tqR&5*y`1k!79j;$m-q5j&ELC@~6 zd1DFIwvG_it(t<>iIh^iv@LGqR&aC7;!JV+$)EMpJkaVLjZyZF7k}s8bE$s_^p!Os z1aRp6F#KLpCbimGspFZj3VtJ5=juFoJjnf_2+7C$x?*NI+EKP7sHBCpYWP;@+|#0z z$$_zGKlkz%<)YNo@YaVznSFN4NGOGTZV)u@?IRZ`=6&P)J^$QjuSH zfvw?)^tGc04_IB*PrvZt7lCZxI+!97E&`bIOzke?(C^x3sug3)j=?BYcl+_0aechNOwn6bQV>2XbHsdUn zVoQ4K6;lw_BYEM0nxi-EO>K}_A;1v^TcYVtULY*9D*d7WTeyUc)UhbOlu zy4#w{_eeZe*(BaI$uQ1#V``##=<%n;^7@8PLBYMD8Ev)~?p=4Qt<9WY&8}9W3yhj3 zi!!t_>@XzEE!OP%CS&0!g3a=0m#@?|bToA3ESCBtb5<+M`;}qYzs-b~#dHt~$uXqto!IV8y!7_9?tjI*Sl6-wTvYo4D3Ey_ObnH=Q!vhBfRQkSX+Q)$SRGT|# z)Kb(Ll?p{$mi(M6H{Qx$*4O!MoT*00d~MOMGRUVq{l@r)_&Y7t z;|-c3^0cTJgpfv-ps(wz?{{|N1h}i$e|Gnu8khKL^Z(Q2|3d$7mw#pgzkr=~>$jl) z+w6aj|7VZ?%)`HX1n;KgxAgd@bc8wa3w);W?q03kv1 Date: Fri, 17 Apr 2020 08:40:50 +0000 Subject: [PATCH 2/4] Add files via upload --- README.md | 50 ++++------------- Untitled4.ipynb | 139 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+), 41 deletions(-) create mode 100644 Untitled4.ipynb diff --git a/README.md b/README.md index d3696d5..d0eea52 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,9 @@ -# ML-Logistic-regression-algorithm-challenge - - -![DSN logo](DSN_logo.png)|DSN Algorithm Challenge| -|---|---| - -A lot of data scientists or machine learning enthusiasts do use various machine learning algorithms as a black box without knowing how they work or the mathematics behind it. The purpose of this challenge is to encourage the mathematical understanding of machine learning algorithms, their break and yield point. - -In summary, participants are encouraged to understand the fundamental concepts behind machine learning algorithms/models. - - -The rules and guidelines for this challenge are as follows: - -1. Ensure to register at https://bit.ly/dsnmlhack - -2. The algorithm challenge is open to all. - -3. Participants are expected to design and develop the Logistic Regression algorithm from scratch using Python or R programming. - -4. For python developers (numpy is advisable). - -5. To push your solution to us, make a [pull request](https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests) to DSN's GitHub page at https://www.github.com/datasciencenigeria/ML-Logistic-regression-algorithm-challenge. Ensure to add your readme file to understand your code. - -6. The top 3 optimized code will be compensated as follows: - -- **1st position**: 20GB data plan. -- **2nd position**: 15GB data plan. -- **3rd position**: 10GB data plan. - -7. Add your scripts and readme.MD file as a folder saved as your full name (surname_first_middle name) by making a pull request to the repository. - ---- -For issues on this challenge kindly reach out to the AI+campus/city managers - -**Twitter**: [@DataScienceNIG](https://twitter.com/DataScienceNIG), [@elishatofunmi](https://twitter.com/Elishatofunmi), [@o_funminiyi](https://twitter.com/o_funminiyi), [@gbganalyst](https://twitter.com/gbganalyst) - -or - -**Call**: +2349062000119,+2349080564419. - -Good luck! +# olawale_abdulrasheed_olamide +consider a dataset with multiple feature these features are related, this relation wed refer to as weight , +the relation between these features lets us determine its outcome(in this case ,classifying). +logistic regression is a widely used algorithm for classification. +i'll be walking through the steps that makes it acomplish it's goals. +Making use of sigmoid fuction a logistic regression predicts an outcome between 0 and 1. +but in the case of our classification , it is to be used to predict wheather or not some features fit in a particular group (0 or 1). taking a threshold of 0.5 (personal preference) and groping based on that , any feature less than the threshold is to be grouped seperately from one greater than or equal to the threshold. +our fuction determined, we can now determine our weights (relationship of the features,some are more important than others ,hence larger weight) +now,the problem is getting the best weights since we have no idea what it is. we cant brute force our way through (thats alot), but we can use gradient descent which its name suggest we descend gradually till minimal and almost optimal weights ,using its loss function ,gradually descendimg with its learning rate(so as not to overstep the minimum).by comparing the loss and continuosly adjusting the weights to minimize this loss (number of time you check and update is to be determined by you ofcourse) diff --git a/Untitled4.ipynb b/Untitled4.ipynb new file mode 100644 index 0000000..2761474 --- /dev/null +++ b/Untitled4.ipynb @@ -0,0 +1,139 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [], + "source": [ + "class logistic_regression():\n", + " #terms we'll use -epochs (how many times well descend or ascend to get our bwst weights)\n", + "#learning_rate = amount how fast we descend\n", + " def __init__(self,epochs=1000,learning_rate=0.001):\n", + " self.epochs = epochs\n", + " self.learning_rate = learning_rate\n", + " \n", + " \n", + " def fit(self,x,y):\n", + " #first we guess weights to pass our sigmoid function (we intialize our weight)\n", + " self.weights = np.zeros((x.shape[1]))\n", + " for i in range(self.epochs):\n", + " z = np.dot(x,self.weights)\n", + " #new prediction\n", + " self.y_new = (1/(1+ np.exp(-z)))\n", + " self.gradient = np.dot(x.T,(self.y_new-y))/y.shape\n", + " self.weights = self.weights - self.learning_rate*self.gradient\n", + " \n", + " def predict(self,x):\n", + " \n", + " z=np.dot(x,self.weights)\n", + " y = (1/(1+ np.exp(-z)))\n", + " return y>=0.5\n", + " \n", + " def confirm(self,y1,y):\n", + " return (y1==y).mean()\n", + " \n", + "\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "from sklearn.datasets import load_breast_cancer\n", + "breast = load_breast_cancer()\n", + "x = breast.data\n", + "y = breast.target" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/olamide/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:15: RuntimeWarning: overflow encountered in exp\n", + " from ipykernel import kernelapp as app\n" + ] + } + ], + "source": [ + "import numpy as np\n", + "ola = logistic_regression()\n", + "ola.fit(x,y)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/olamide/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:22: RuntimeWarning: overflow encountered in exp\n" + ] + } + ], + "source": [ + "p = ola.predict(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.9191564147627417" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ola.confirm(p,y)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From 6c4821bf831639c5e74dccffd1ef0e8fc3d94c04 Mon Sep 17 00:00:00 2001 From: proflamyt <53262578+proflamyt@users.noreply.github.com> Date: Fri, 17 Apr 2020 08:41:39 +0000 Subject: [PATCH 3/4] Delete olawale_abdulrasheed_olamide-master.zip --- olawale_abdulrasheed_olamide-master.zip | Bin 2337 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 olawale_abdulrasheed_olamide-master.zip diff --git a/olawale_abdulrasheed_olamide-master.zip b/olawale_abdulrasheed_olamide-master.zip deleted file mode 100644 index bc7d29e2530d2115971b520090f5831de9376833..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2337 zcmb7_c{mjKAIE3h=Z28vNRD-c!DL2}D|Z;yI3m+rGOkH8XcsAMB{>H}D?+4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IOzke?(C^x3sug3)j=?BYcl+_0aechNOwn6bQV>2XbHsdUn zVoQ4K6;lw_BYEM0nxi-EO>K}_A;1v^TcYVtULY*9D*d7WTeyUc)UhbOlu zy4#w{_eeZe*(BaI$uQ1#V``##=<%n;^7@8PLBYMD8Ev)~?p=4Qt<9WY&8}9W3yhj3 zi!!t_>@XzEE!OP%CS&0!g3a=0m#@?|bToA3ESCBtb5<+M`;}qYzs-b~#dHt~$uXqto!IV8y!7_9?tjI*Sl6-wTvYo4D3Ey_ObnH=Q!vhBfRQkSX+Q)$SRGT|# z)Kb(Ll?p{$mi(M6H{Qx$*4O!MoT*00d~MOMGRUVq{l@r)_&Y7t z;|-c3^0cTJgpfv-ps(wz?{{|N1h}i$e|Gnu8khKL^Z(Q2|3d$7mw#pgzkr=~>$jl) z+w6aj|7VZ?%)`HX1n;KgxAgd@bc8wa3w);W?q03kv1 Date: Wed, 22 Apr 2020 01:40:37 +0000 Subject: [PATCH 4/4] Update Untitled4.ipynb --- Untitled4.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Untitled4.ipynb b/Untitled4.ipynb index 2761474..ff3be13 100644 --- a/Untitled4.ipynb +++ b/Untitled4.ipynb @@ -16,7 +16,7 @@ " \n", " def fit(self,x,y):\n", " #first we guess weights to pass our sigmoid function (we intialize our weight)\n", - " self.weights = np.zeros((x.shape[1]))\n", + " self.weights = 2*np.random.random((x.shape[1],x.shape[0]))-1\n", " for i in range(self.epochs):\n", " z = np.dot(x,self.weights)\n", " #new prediction\n",