add all files
This commit is contained in:
197
exercises/First Deep Learning Model commented.ipynb
Normal file
197
exercises/First Deep Learning Model commented.ipynb
Normal file
@@ -0,0 +1,197 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# First Deep Learning Model"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### Imports"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import numpy as np # import the numpy library and assign the name np to it\n",
|
||||
"%matplotlib inline # magic function that sets the backend of matplotlib to the inline backend\n",
|
||||
"import matplotlib.pyplot as plt # import the matplotlib.pyplot and assign the name plt to it"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from sklearn.datasets import make_circles # import the make_circles module from the sklearn.datasets module"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"X, y = make_circles(n_samples=1000,\n",
|
||||
" noise=0.1,\n",
|
||||
" factor=0.2,\n",
|
||||
" random_state=0)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"X"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"X.shape"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.figure(figsize=(5, 5))\n",
|
||||
"plt.plot(X[y==0, 0], X[y==0, 1], 'ob', alpha=0.5)\n",
|
||||
"plt.plot(X[y==1, 0], X[y==1, 1], 'xr', alpha=0.5)\n",
|
||||
"plt.xlim(-1.5, 1.5)\n",
|
||||
"plt.ylim(-1.5, 1.5)\n",
|
||||
"plt.legend(['0', '1'])\n",
|
||||
"plt.title(\"Blue circles and Red crosses\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from tensorflow.keras.models import Sequential\n",
|
||||
"from tensorflow.keras.layers import Dense\n",
|
||||
"from tensorflow.keras.optimizers import SGD"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model = Sequential()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model.add(Dense(4, input_shape=(2,), activation='tanh'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model.add(Dense(1, activation='sigmoid'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model.compile(SGD(learning_rate=0.5), 'binary_crossentropy', metrics=['accuracy'])"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model.fit(X, y, epochs=20)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"hticks = np.linspace(-1.5, 1.5, 101)\n",
|
||||
"vticks = np.linspace(-1.5, 1.5, 101)\n",
|
||||
"aa, bb = np.meshgrid(hticks, vticks)\n",
|
||||
"ab = np.c_[aa.ravel(), bb.ravel()]\n",
|
||||
"c = model.predict(ab)\n",
|
||||
"cc = c.reshape(aa.shape)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"plt.figure(figsize=(5, 5))\n",
|
||||
"plt.contourf(aa, bb, cc, cmap='bwr', alpha=0.2)\n",
|
||||
"plt.plot(X[y==0, 0], X[y==0, 1], 'ob', alpha=0.5)\n",
|
||||
"plt.plot(X[y==1, 0], X[y==1, 1], 'xr', alpha=0.5)\n",
|
||||
"plt.xlim(-1.5, 1.5)\n",
|
||||
"plt.ylim(-1.5, 1.5)\n",
|
||||
"plt.legend(['0', '1'])\n",
|
||||
"plt.title(\"Blue circles and Red crosses\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"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.10"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
2604
exercises/Jupyter notebook CVML.ipynb
Normal file
2604
exercises/Jupyter notebook CVML.ipynb
Normal file
File diff suppressed because one or more lines are too long
6
exercises/Untitled.ipynb
Normal file
6
exercises/Untitled.ipynb
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"cells": [],
|
||||
"metadata": {},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user