Skip to content

Commit

Permalink
added regularization
Browse files Browse the repository at this point in the history
  • Loading branch information
akagam1 committed Feb 10, 2022
1 parent 968c062 commit c9ecf98
Show file tree
Hide file tree
Showing 26 changed files with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions Neural Networks/OneVsAll-Digit Recognition.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": 153,
"execution_count": 2,
"id": "aeaa3bba",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -240,7 +240,7 @@
"[5 rows x 785 columns]"
]
},
"execution_count": 153,
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -257,7 +257,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 3,
"id": "6c91a3f5",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -324,7 +324,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 4,
"id": "26597be5",
"metadata": {},
"outputs": [],
Expand All @@ -336,7 +336,7 @@
},
{
"cell_type": "code",
"execution_count": 141,
"execution_count": 5,
"id": "a1f43228",
"metadata": {},
"outputs": [
Expand All @@ -346,7 +346,7 @@
"(5000, 785)"
]
},
"execution_count": 141,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -361,37 +361,38 @@
},
{
"cell_type": "code",
"execution_count": 142,
"execution_count": 10,
"id": "fa042365",
"metadata": {},
"outputs": [],
"source": [
"def gradDesc(theta,x,y,m):\n",
"def gradDesc(theta,x,y,m,lambda_):\n",
" h = sigmoid(x*theta)\n",
" grad = np.transpose(x)*(h-np.transpose(y))\n",
" grad[1:,:] = grad[1:,:] + (lambda_/m)*theta[1:,:]\n",
" return grad/m\n",
"\n",
"def oneVall(x,y,alpha,itr):\n",
"def oneVall(x,y,alpha,itr,lambda_):\n",
" m,n = x.shape\n",
" theta = np.transpose(np.matrix(np.zeros(n)))\n",
" x = np.matrix(x)\n",
" y = np.matrix(y)\n",
" for i in range(itr):\n",
" theta = theta - alpha*gradDesc(theta,x,y,m)\n",
" theta = theta - alpha*gradDesc(theta,x,y,m,lambda_)\n",
" return np.array(np.transpose(theta))"
]
},
{
"cell_type": "code",
"execution_count": 147,
"execution_count": 15,
"id": "d31d0b48",
"metadata": {},
"outputs": [],
"source": [
"all_theta = np.array([np.zeros(785)])\n",
"for j in range(num_labels):\n",
" yIn = (y == j).astype(int)\n",
" temp = oneVall(x,yIn,0.00000001,1000)\n",
" temp = oneVall(x,yIn,0.00000001,1000,100)\n",
" all_theta = np.append(all_theta, temp, axis=0)\n",
" #all_theta = np.vstack([all_theta,temp])\n",
"all_theta.shape\n",
Expand All @@ -400,7 +401,7 @@
},
{
"cell_type": "code",
"execution_count": 154,
"execution_count": 16,
"id": "1b610409",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -433,7 +434,7 @@
},
{
"cell_type": "code",
"execution_count": 163,
"execution_count": 17,
"id": "37e5c59c",
"metadata": {},
"outputs": [],
Expand All @@ -443,7 +444,7 @@
},
{
"cell_type": "code",
"execution_count": 164,
"execution_count": 18,
"id": "fbb3bb20",
"metadata": {},
"outputs": [
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c9ecf98

Please sign in to comment.