Skip to content

Commit

Permalink
fix ex2 sol
Browse files Browse the repository at this point in the history
  • Loading branch information
wassname committed Nov 3, 2020
1 parent b8e533f commit f977a2b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 46 deletions.
112 changes: 68 additions & 44 deletions notebooks/c01_Intro_to_NN_Part_1/Intro_to_NN_Part_1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,18 @@
" return clf"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"ExecuteTime": {
"end_time": "2020-11-03T03:44:09.664941Z",
"start_time": "2020-11-03T03:44:09.557535Z"
}
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 28,
Expand Down Expand Up @@ -576,27 +588,27 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 37,
"metadata": {
"ExecuteTime": {
"end_time": "2020-11-03T03:39:15.060053Z",
"start_time": "2020-11-03T03:39:14.655024Z"
"end_time": "2020-11-03T03:46:15.168823Z",
"start_time": "2020-11-03T03:46:14.536734Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"0.7148148148148148"
"0.587037037037037"
]
},
"execution_count": 29,
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hidden_layers = 10\n",
"hidden_layers = [32, 10]\n",
"\n",
"# Let's train the model using our custom hyperparameters\n",
"clf = train(X_train, y_train, hidden_layers, activation, solver)\n",
Expand Down Expand Up @@ -650,14 +662,26 @@
" for num_hidden_layers in hyperparameters['hidden_layers']:\n",
" print(f'Train NN with solver:{solver}, activation:{activation} and Number of hidden layers:{num_hidden_layers}')\n",
" # Let's train the model using our custom hyperparameters\n",
" clf = train(X_train, y_train, num_hidden_layers, activation)\n",
" clf = train(X_train, y_train, num_hidden_layers, activation, solver)\n",
" # Let's evaluate the accuracy of the model using the test data\n",
" print('Accuracy:',clf.score(X_test, y_test))\n",
"```\n",
"\n",
"</details>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-11-03T03:50:02.310907Z",
"start_time": "2020-11-03T03:49:40.529325Z"
}
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -692,23 +716,23 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 44,
"metadata": {
"ExecuteTime": {
"end_time": "2020-11-03T03:34:42.059502Z",
"start_time": "2020-11-03T03:34:34.291609Z"
"end_time": "2020-11-03T05:05:38.141129Z",
"start_time": "2020-11-03T05:05:38.137422Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([[3.0750e-01, 1.7755e-01, 4.9070e-01],\n",
" [1.6806e-01, 4.2704e-01, 1.8621e-01],\n",
" [3.7235e-04, 2.2258e-01, 8.0673e-01],\n",
" [6.3377e-01, 1.4874e-02, 2.7018e-01],\n",
" [4.9504e-01, 4.3858e-01, 1.6609e-02]])\n"
"tensor([[0.5503, 0.4693, 0.7043],\n",
" [0.4956, 0.8336, 0.9000],\n",
" [0.6549, 0.7137, 0.4605],\n",
" [0.0462, 0.2258, 0.0047],\n",
" [0.1696, 0.1850, 0.6982]])\n"
]
}
],
Expand All @@ -730,11 +754,11 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 53,
"metadata": {
"ExecuteTime": {
"end_time": "2020-11-03T03:34:42.076298Z",
"start_time": "2020-11-03T03:34:42.061886Z"
"end_time": "2020-11-03T05:08:38.124103Z",
"start_time": "2020-11-03T05:08:38.120418Z"
}
},
"outputs": [
Expand All @@ -760,19 +784,19 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 54,
"metadata": {
"ExecuteTime": {
"end_time": "2020-11-03T03:34:42.126772Z",
"start_time": "2020-11-03T03:34:42.077926Z"
"end_time": "2020-11-03T05:08:38.615472Z",
"start_time": "2020-11-03T05:08:38.611286Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([ 1.4927, -0.8089])\n"
"tensor([-0.6106, 1.8554])\n"
]
}
],
Expand All @@ -783,11 +807,11 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 55,
"metadata": {
"ExecuteTime": {
"end_time": "2020-11-03T03:34:42.172765Z",
"start_time": "2020-11-03T03:34:42.128057Z"
"end_time": "2020-11-03T05:08:38.760225Z",
"start_time": "2020-11-03T05:08:38.757628Z"
}
},
"outputs": [
Expand Down Expand Up @@ -820,19 +844,19 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 56,
"metadata": {
"ExecuteTime": {
"end_time": "2020-11-03T03:34:42.220396Z",
"start_time": "2020-11-03T03:34:42.174080Z"
"end_time": "2020-11-03T05:08:40.082228Z",
"start_time": "2020-11-03T05:08:40.078405Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([ 1.4927, -0.8089]) tensor([0.0388, 0.2797])\n"
"tensor([-0.6106, 1.8554]) tensor([0.4771, 0.7711])\n"
]
}
],
Expand All @@ -843,21 +867,21 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 57,
"metadata": {
"ExecuteTime": {
"end_time": "2020-10-02T05:11:58.844978Z",
"start_time": "2020-10-02T05:11:58.840069Z"
"end_time": "2020-11-03T05:08:41.444623Z",
"start_time": "2020-11-03T05:08:41.440870Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"tensor([0.4458, 0.8197])"
"tensor([-0.1335, 2.6266])"
]
},
"execution_count": 32,
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -875,19 +899,19 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 58,
"metadata": {
"ExecuteTime": {
"end_time": "2020-10-02T05:12:01.647091Z",
"start_time": "2020-10-02T05:12:01.635378Z"
"end_time": "2020-11-03T05:08:43.178190Z",
"start_time": "2020-11-03T05:08:43.174471Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([0.4458, 0.8197])\n"
"tensor([-0.1335, 2.6266])\n"
]
}
],
Expand All @@ -897,21 +921,21 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 59,
"metadata": {
"ExecuteTime": {
"end_time": "2020-10-02T05:12:10.536381Z",
"start_time": "2020-10-02T05:12:10.527378Z"
"end_time": "2020-11-03T05:08:43.497960Z",
"start_time": "2020-11-03T05:08:43.493299Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor([0.0371, 0.1456])\n",
"tensor([ 0.2243, -0.2993])\n",
"tensor([3.0254, 0.4651])\n"
"tensor([-0.2913, 1.4308])\n",
"tensor([-1.0877, 1.0843])\n",
"tensor([-1.2798, 2.4062])\n"
]
}
],
Expand Down
7 changes: 5 additions & 2 deletions notebooks/c01_Intro_to_NN_Part_1/Intro_to_NN_Part_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def train(X_train, y_train, hidden_layers, activation, solver):
return clf



# +
hidden_layers = 2
activation = "relu" # ReLU Activation function
Expand All @@ -240,7 +241,7 @@ def train(X_train, y_train, hidden_layers, activation, solver):
# We got an accuracy of 28.3%, which is not really great. Let's try again and train a model changing the number of hidden layers to 10.

# +
hidden_layers = 10
hidden_layers = [32, 10]

# Let's train the model using our custom hyperparameters
clf = train(X_train, y_train, hidden_layers, activation, solver)
Expand Down Expand Up @@ -281,13 +282,15 @@ def train(X_train, y_train, hidden_layers, activation, solver):
# for num_hidden_layers in hyperparameters['hidden_layers']:
# print(f'Train NN with solver:{solver}, activation:{activation} and Number of hidden layers:{num_hidden_layers}')
# # Let's train the model using our custom hyperparameters
# clf = train(X_train, y_train, num_hidden_layers, activation)
# clf = train(X_train, y_train, num_hidden_layers, activation, solver)
# # Let's evaluate the accuracy of the model using the test data
# print('Accuracy:',clf.score(X_test, y_test))
# ```
#
# </details>



# <a name="3"></a>
# # 3. Introduction to Pytorch
#
Expand Down

0 comments on commit f977a2b

Please sign in to comment.