Skip to content

Commit

Permalink
Created using Colaboratory
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-mushtaq committed Dec 12, 2021
1 parent 582223c commit d0a1d87
Showing 1 changed file with 143 additions and 1 deletion.
144 changes: 143 additions & 1 deletion Deep_Learning_with_Keras.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Deep Learning with Keras.ipynb",
"provenance": [],
"toc_visible": true,
"authorship_tag": "ABX9TyOLkE+hdqdRX8cgCtJtjxG8",
"authorship_tag": "ABX9TyOCE+218HmLIwAzK7jJWRu4",
"include_colab_link": true
},
"kernelspec": {
Expand Down Expand Up @@ -3138,6 +3138,148 @@
"id": "F-3mZgPxEVxU"
}
},
{
"cell_type": "markdown",
"source": [
"#### **3.4.1 Preparing a model for tuning**\n"
],
"metadata": {
"id": "GONIG6nQkEgj"
}
},
{
"cell_type": "markdown",
"source": [
"Let's tune the hyperparameters of a binary classification model that does well classifying the breast cancer dataset.\n",
"\n",
"You've seen that the first step to turn a model into a sklearn estimator is to build a function that creates it. The definition of this function is important since hyperparameter tuning is carried out by varying the arguments your function receives.\n",
"\n",
"Build a simple create_model() function that receives both a learning rate and an activation function as arguments. The Adam optimizer has been imported as an object from keras.optimizers so that you can also change its learning rate parameter."
],
"metadata": {
"id": "WT5FtkXlkLAU"
}
},
{
"cell_type": "markdown",
"source": [
"**Instruction**"
],
"metadata": {
"id": "Lyxa_AZykQb0"
}
},
{
"cell_type": "markdown",
"source": [
"- Set the learning rate of the Adam optimizer object to the one passed in the arguments.\n",
"- Set the hidden layers activations to the one passed in the arguments.\n",
"- Pass the optimizer and the binary cross-entropy loss to the .compile() method."
],
"metadata": {
"id": "CPfPyRlAkr3M"
}
},
{
"cell_type": "markdown",
"source": [
"**Hints**"
],
"metadata": {
"id": "OLG28CShkwxS"
}
},
{
"cell_type": "markdown",
"source": [
"- The optimizer is stored in the variable opt.\n",
"- The loss function needs to be written as a string: 'binary_crossentropy'."
],
"metadata": {
"id": "LF3Xckekk2BD"
}
},
{
"cell_type": "markdown",
"source": [
"![](https://drive.google.com/uc?export=view&id=1lK_K0dlwoX6a9fd0Mc6T6-K8ohTs2_kA)"
],
"metadata": {
"id": "O1VwCEH3l7Pi"
}
},
{
"cell_type": "markdown",
"source": [
"#### **3.4.2 Tuning the model parameters**\n"
],
"metadata": {
"id": "pow2Xl96mPHZ"
}
},
{
"cell_type": "markdown",
"source": [
"It's time to try out different parameters on your model and see how well it performs!\n",
"\n",
"The create_model() function you built in the previous exercise is ready for you to use.\n",
"\n",
"Since fitting the RandomizedSearchCV object would take too long, the results you'd get are printed in the show_results() function. You could try random_search.fit(X,y) in the console yourself to check it does work after you have built everything else, but you will probably timeout the exercise (so copy your code first if you try this or you can lose your progress!).\n",
"\n",
"You don't need to use the optional epochs and batch_size parameters when building your KerasClassifier object since you are passing them as params to the random search and this works already."
],
"metadata": {
"id": "GikxvxXCmZtB"
}
},
{
"cell_type": "markdown",
"source": [
"**instruction**"
],
"metadata": {
"id": "j3K6OV2xmbqw"
}
},
{
"cell_type": "markdown",
"source": [
"- Import KerasClassifier from keras scikit_learn wrappers.\n",
"- Use your create_model function when instantiating your KerasClassifier.\n",
"- Set 'relu' and 'tanh' as activation, 32, 128, and 256 as batch_size, 50, 100, and 200 epochs, and learning_rate of 0.1, 0.01, and 0.001.\n",
"- Pass your converted model and the chosen params as you build your RandomizedSearchCV object."
],
"metadata": {
"id": "MBr383G-mi7x"
}
},
{
"cell_type": "markdown",
"source": [
"**Hints**"
],
"metadata": {
"id": "Y5B8FTuBmrih"
}
},
{
"cell_type": "markdown",
"source": [
"Activation functions are defined as a list of strings whilst batch_size, epochs and learning rates are defined as lists of numbers."
],
"metadata": {
"id": "-Ru0yIcZmxrx"
}
},
{
"cell_type": "markdown",
"source": [
"![](https://drive.google.com/uc?export=view&id=1U707fEaf6iipZSrtcQEcBrtTdbsnhIWG)"
],
"metadata": {
"id": "H7DDlqRDpjm4"
}
},
{
"cell_type": "markdown",
"metadata": {
Expand Down

0 comments on commit d0a1d87

Please sign in to comment.