diff --git a/your-code/Screen Shot 2021-03-19 at 00.06.11.png b/your-code/Screen Shot 2021-03-19 at 00.06.11.png
new file mode 100644
index 0000000..69b4c5f
Binary files /dev/null and b/your-code/Screen Shot 2021-03-19 at 00.06.11.png differ
diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb
index 2487c5f..b88692c 100644
--- a/your-code/challenge-1.ipynb
+++ b/your-code/challenge-1.ipynb
@@ -34,11 +34,221 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
- "# your code here"
+ "# your code here\n",
+ "import pandas as pd\n",
+ "data = pd.read_csv('tic-tac-toe.csv')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 3,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " TL | \n",
+ " TM | \n",
+ " TR | \n",
+ " ML | \n",
+ " MM | \n",
+ " MR | \n",
+ " BL | \n",
+ " BM | \n",
+ " BR | \n",
+ " class | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " o | \n",
+ " x | \n",
+ " o | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " o | \n",
+ " o | \n",
+ " x | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " o | \n",
+ " b | \n",
+ " b | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " b | \n",
+ " o | \n",
+ " b | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " TL TM TR ML MM MR BL BM BR class\n",
+ "0 x x x x o o x o o True\n",
+ "1 x x x x o o o x o True\n",
+ "2 x x x x o o o o x True\n",
+ "3 x x x x o o o b b True\n",
+ "4 x x x x o o b o b True"
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "data.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "\n",
+ "RangeIndex: 958 entries, 0 to 957\n",
+ "Data columns (total 10 columns):\n",
+ " # Column Non-Null Count Dtype \n",
+ "--- ------ -------------- ----- \n",
+ " 0 TL 958 non-null object\n",
+ " 1 TM 958 non-null object\n",
+ " 2 TR 958 non-null object\n",
+ " 3 ML 958 non-null object\n",
+ " 4 MM 958 non-null object\n",
+ " 5 MR 958 non-null object\n",
+ " 6 BL 958 non-null object\n",
+ " 7 BM 958 non-null object\n",
+ " 8 BR 958 non-null object\n",
+ " 9 class 958 non-null bool \n",
+ "dtypes: bool(1), object(9)\n",
+ "memory usage: 68.4+ KB\n"
+ ]
+ }
+ ],
+ "source": [
+ "data.info()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for column in data.columns:\n",
+ " data[column] = data[column].replace('b',0).replace('x',1).replace('o',2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "y = data['class']\n",
+ "X = data.drop('class',axis=1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "X_norm = X/2"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 30,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(958, 9)"
+ ]
+ },
+ "execution_count": 30,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "X_norm.shape"
]
},
{
@@ -60,11 +270,103 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 49,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# your code here\n",
+ "from sklearn.model_selection import train_test_split\n",
+ "X_train, X_test, y_train, y_test = train_test_split(X_norm, y, test_size=0.2, random_state=0)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 50,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from keras.models import Sequential\n",
+ "from keras.layers import Dense\n",
+ "model = Sequential()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 51,
"metadata": {},
"outputs": [],
"source": [
- "# your code here"
+ "model.compile(\n",
+ " optimizer='adam',\n",
+ " loss='sparse_categorical_crossentropy',\n",
+ " metrics=['accuracy'])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 52,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "24/24 [==============================] - 0s 1ms/step - loss: 5.8859 - accuracy: 0.3290\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 52,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "model.fit(X_train,y_train)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 53,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "6/6 [==============================] - 0s 2ms/step - loss: 5.4945 - accuracy: 0.3438\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "[5.494471073150635, 0.34375]"
+ ]
+ },
+ "execution_count": 53,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "model.evaluate(X_test,y_test)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 54,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "model.save_weights('tic-tac-toe.model')"
]
},
{
@@ -78,11 +380,61 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 55,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 55,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# your code here\n",
+ "model.load_weights('tic-tac-toe.model')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 67,
"metadata": {},
"outputs": [],
"source": [
- "# your code here"
+ "predictions = model.predict(y_test[:5])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 68,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "[[False]\n",
+ " [ True]\n",
+ " [ True]\n",
+ " [ True]\n",
+ " [ True]]\n",
+ "879 False\n",
+ "496 True\n",
+ "14 True\n",
+ "546 True\n",
+ "55 True\n",
+ "Name: class, dtype: bool\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "print(predictions)\n",
+ "print(y_test[:5])"
]
},
{
@@ -104,11 +456,184 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 227,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import tensorflow as tf"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 228,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 228,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "# your code here\n",
+ "model = Sequential()\n",
+ "model.add(tf.keras.layers.Dense(2))\n",
+ "tf.keras.optimizers.Adam(learning_rate=0.001)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 229,
"metadata": {},
"outputs": [],
"source": [
- "# your code here"
+ "model.compile(optimizer='adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 230,
+ "metadata": {
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Epoch 1/40\n",
+ "WARNING:tensorflow:Layer dense_42 is casting an input tensor from dtype float64 to the layer's dtype of float32, which is new behavior in TensorFlow 2. The layer has dtype float32 because its dtype defaults to floatx.\n",
+ "\n",
+ "If you intended to run this layer in float32, you can safely ignore this warning. If in doubt, this warning is likely only an issue if you are porting a TensorFlow 1.X model to TensorFlow 2.\n",
+ "\n",
+ "To change all layers to have dtype float64 by default, call `tf.keras.backend.set_floatx('float64')`. To change just this layer, pass dtype='float64' to the layer constructor. If you are the author of this layer, you can disable autocasting by passing autocast=False to the base Layer constructor.\n",
+ "\n",
+ "24/24 [==============================] - 0s 1ms/step - loss: 0.7182 - accuracy: 0.5104\n",
+ "Epoch 2/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6892 - accuracy: 0.5131\n",
+ "Epoch 3/40\n",
+ "24/24 [==============================] - 0s 3ms/step - loss: 0.6809 - accuracy: 0.5313\n",
+ "Epoch 4/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6591 - accuracy: 0.5444\n",
+ "Epoch 5/40\n",
+ "24/24 [==============================] - 0s 1ms/step - loss: 0.6543 - accuracy: 0.5561\n",
+ "Epoch 6/40\n",
+ "24/24 [==============================] - 0s 4ms/step - loss: 0.6510 - accuracy: 0.5640: 0s - loss: 0.6569 - accuracy: 0.54\n",
+ "Epoch 7/40\n",
+ "24/24 [==============================] - 0s 1ms/step - loss: 0.6488 - accuracy: 0.5783\n",
+ "Epoch 8/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6471 - accuracy: 0.5888\n",
+ "Epoch 9/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6456 - accuracy: 0.5940\n",
+ "Epoch 10/40\n",
+ "24/24 [==============================] - 0s 1ms/step - loss: 0.6439 - accuracy: 0.5992\n",
+ "Epoch 11/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6425 - accuracy: 0.6057\n",
+ "Epoch 12/40\n",
+ "24/24 [==============================] - 0s 3ms/step - loss: 0.6411 - accuracy: 0.6149\n",
+ "Epoch 13/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6399 - accuracy: 0.6175\n",
+ "Epoch 14/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6386 - accuracy: 0.6201\n",
+ "Epoch 15/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6375 - accuracy: 0.6227\n",
+ "Epoch 16/40\n",
+ "24/24 [==============================] - 0s 1ms/step - loss: 0.6362 - accuracy: 0.6266\n",
+ "Epoch 17/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6352 - accuracy: 0.6292\n",
+ "Epoch 18/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6344 - accuracy: 0.6332\n",
+ "Epoch 19/40\n",
+ "24/24 [==============================] - 0s 3ms/step - loss: 0.6332 - accuracy: 0.6332\n",
+ "Epoch 20/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6320 - accuracy: 0.6332\n",
+ "Epoch 21/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6311 - accuracy: 0.6371\n",
+ "Epoch 22/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6303 - accuracy: 0.6384\n",
+ "Epoch 23/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6293 - accuracy: 0.6397\n",
+ "Epoch 24/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6286 - accuracy: 0.6397\n",
+ "Epoch 25/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6277 - accuracy: 0.6410\n",
+ "Epoch 26/40\n",
+ "24/24 [==============================] - 0s 1ms/step - loss: 0.6265 - accuracy: 0.6410\n",
+ "Epoch 27/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6254 - accuracy: 0.6410\n",
+ "Epoch 28/40\n",
+ "24/24 [==============================] - 0s 7ms/step - loss: 0.6244 - accuracy: 0.6423\n",
+ "Epoch 29/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6236 - accuracy: 0.6423\n",
+ "Epoch 30/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6227 - accuracy: 0.6436\n",
+ "Epoch 31/40\n",
+ "24/24 [==============================] - 0s 1ms/step - loss: 0.6218 - accuracy: 0.6436\n",
+ "Epoch 32/40\n",
+ "24/24 [==============================] - 0s 6ms/step - loss: 0.6209 - accuracy: 0.6436\n",
+ "Epoch 33/40\n",
+ "24/24 [==============================] - 0s 5ms/step - loss: 0.6198 - accuracy: 0.6436\n",
+ "Epoch 34/40\n",
+ "24/24 [==============================] - 0s 1ms/step - loss: 0.6191 - accuracy: 0.6436\n",
+ "Epoch 35/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6181 - accuracy: 0.6436\n",
+ "Epoch 36/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6173 - accuracy: 0.6436\n",
+ "Epoch 37/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6164 - accuracy: 0.6449\n",
+ "Epoch 38/40\n",
+ "24/24 [==============================] - 0s 1ms/step - loss: 0.6155 - accuracy: 0.6449\n",
+ "Epoch 39/40\n",
+ "24/24 [==============================] - 0s 2ms/step - loss: 0.6148 - accuracy: 0.6462\n",
+ "Epoch 40/40\n",
+ "24/24 [==============================] - 0s 4ms/step - loss: 0.6138 - accuracy: 0.6462\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ ""
+ ]
+ },
+ "execution_count": 230,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "model.fit(X_train,y_train,epochs=40)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 231,
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "6/6 [==============================] - 0s 1ms/step - loss: 0.6233 - accuracy: 0.6146\n"
+ ]
+ },
+ {
+ "data": {
+ "text/plain": [
+ "[0.6233339309692383, 0.6145833134651184]"
+ ]
+ },
+ "execution_count": 231,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "model.evaluate(X_test,y_test)"
]
},
{
@@ -124,7 +649,8 @@
"metadata": {},
"outputs": [],
"source": [
- "# your answer here"
+ "# your answer here\n",
+ "#I believe the epochs helped more to improve the model."
]
}
],
@@ -144,7 +670,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.8.3"
}
},
"nbformat": 4,
diff --git a/your-code/checkpoint b/your-code/checkpoint
new file mode 100644
index 0000000..389afd6
--- /dev/null
+++ b/your-code/checkpoint
@@ -0,0 +1,2 @@
+model_checkpoint_path: "tic-tac-toe.model"
+all_model_checkpoint_paths: "tic-tac-toe.model"
diff --git a/your-code/tic-tac-toe.model.data-00000-of-00001 b/your-code/tic-tac-toe.model.data-00000-of-00001
new file mode 100644
index 0000000..babc080
Binary files /dev/null and b/your-code/tic-tac-toe.model.data-00000-of-00001 differ
diff --git a/your-code/tic-tac-toe.model.index b/your-code/tic-tac-toe.model.index
new file mode 100644
index 0000000..749f0e0
Binary files /dev/null and b/your-code/tic-tac-toe.model.index differ