add all files

This commit is contained in:
Sem van der Hoeven
2021-05-26 15:12:05 +02:00
parent 5c3be10247
commit d979ca38f5
44 changed files with 43574 additions and 0 deletions

View File

@@ -0,0 +1,190 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# First Deep Learning Model"
]
},
{
"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"
]
},
{
"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
}