diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb
index 2487c5f..8caf208 100644
--- a/your-code/challenge-1.ipynb
+++ b/your-code/challenge-1.ipynb
@@ -34,11 +34,546 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {},
- "outputs": [],
+ "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",
+ " | 149 | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " b | \n",
+ " b | \n",
+ " o | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 538 | \n",
+ " b | \n",
+ " o | \n",
+ " x | \n",
+ " o | \n",
+ " x | \n",
+ " o | \n",
+ " x | \n",
+ " x | \n",
+ " b | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 409 | \n",
+ " o | \n",
+ " o | \n",
+ " b | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " b | \n",
+ " o | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 357 | \n",
+ " o | \n",
+ " x | \n",
+ " b | \n",
+ " o | \n",
+ " b | \n",
+ " o | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 708 | \n",
+ " x | \n",
+ " b | \n",
+ " x | \n",
+ " o | \n",
+ " x | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " o | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 32 | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " b | \n",
+ " b | \n",
+ " o | \n",
+ " x | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 364 | \n",
+ " o | \n",
+ " x | \n",
+ " b | \n",
+ " b | \n",
+ " o | \n",
+ " o | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " TL TM TR ML MM MR BL BM BR class\n",
+ "149 x o o x x x b b o True\n",
+ "538 b o x o x o x x b True\n",
+ "409 o o b x x x x b o True\n",
+ "357 o x b o b o x x x True\n",
+ "708 x b x o x x o o o False\n",
+ "32 x x x o o b b o x True\n",
+ "364 o x b b o o x x x True"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "# your code here"
+ "#Libraries and download df\n",
+ "import pandas as pd\n",
+ "import numpy as np\n",
+ "from sklearn import preprocessing\n",
+ "from sklearn.model_selection import train_test_split\n",
+ "\n",
+ "from sklearn.exceptions import ConvergenceWarning\n",
+ "from sklearn.neural_network import MLPClassifier\n",
+ "\n",
+ "ttt = pd.read_csv(\"tic-tac-toe.csv\")\n",
+ "ttt.sample(7)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "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",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " | 0 | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " o | \n",
+ " x | \n",
+ " o | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " o | \n",
+ " o | \n",
+ " x | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " o | \n",
+ " b | \n",
+ " b | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " x | \n",
+ " o | \n",
+ " o | \n",
+ " b | \n",
+ " o | \n",
+ " b | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " TL TM TR ML MM MR BL BM BR\n",
+ "0 x x x x o o x o o\n",
+ "1 x x x x o o o x o\n",
+ "2 x x x x o o o o x\n",
+ "3 x x x x o o o b b\n",
+ "4 x x x x o o b o b"
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#Selecting the Categorical columns\n",
+ "obj_df = ttt.select_dtypes(include=['object']).copy()\n",
+ "obj_df.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "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",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 1 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 3 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 0 | \n",
+ " 0 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | 4 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 0 | \n",
+ " 1 | \n",
+ " 0 | \n",
+ " True | \n",
+ "
\n",
+ " \n",
+ " | ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ " ... | \n",
+ "
\n",
+ " \n",
+ " | 953 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 954 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 955 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 956 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ " | 957 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " 1 | \n",
+ " 1 | \n",
+ " 2 | \n",
+ " 2 | \n",
+ " False | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
958 rows × 10 columns
\n",
+ "
"
+ ],
+ "text/plain": [
+ " TL TM TR ML MM MR BL BM BR class\n",
+ "0 2 2 2 2 1 1 2 1 1 True\n",
+ "1 2 2 2 2 1 1 1 2 1 True\n",
+ "2 2 2 2 2 1 1 1 1 2 True\n",
+ "3 2 2 2 2 1 1 1 0 0 True\n",
+ "4 2 2 2 2 1 1 0 1 0 True\n",
+ ".. .. .. .. .. .. .. .. .. .. ...\n",
+ "953 1 2 2 2 1 1 1 2 2 False\n",
+ "954 1 2 1 2 2 1 2 1 2 False\n",
+ "955 1 2 1 2 1 2 2 1 2 False\n",
+ "956 1 2 1 1 2 2 2 1 2 False\n",
+ "957 1 1 2 2 2 1 1 2 2 False\n",
+ "\n",
+ "[958 rows x 10 columns]"
+ ]
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#Convcerting tthe categories into nums\n",
+ "le = preprocessing.LabelEncoder()\n",
+ "\n",
+ "for col in obj_df:\n",
+ " le.fit(ttt[col])\n",
+ " ttt[col]=le.transform(ttt[col])\n",
+ "\n",
+ "ttt"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "array([[ 1.00322257, 1.08495342, 1.00322257, ..., 1.00322257,\n",
+ " -0.16731812, -0.28682739],\n",
+ " [ 1.00322257, 1.08495342, 1.00322257, ..., -0.28682739,\n",
+ " 1.08495342, -0.28682739],\n",
+ " [ 1.00322257, 1.08495342, 1.00322257, ..., -0.28682739,\n",
+ " -0.16731812, 1.00322257],\n",
+ " ...,\n",
+ " [-0.28682739, 1.08495342, -0.28682739, ..., 1.00322257,\n",
+ " -0.16731812, 1.00322257],\n",
+ " [-0.28682739, 1.08495342, -0.28682739, ..., 1.00322257,\n",
+ " -0.16731812, 1.00322257],\n",
+ " [-0.28682739, -0.16731812, 1.00322257, ..., -0.28682739,\n",
+ " 1.08495342, 1.00322257]])"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "#Preparing them datas\n",
+ "x = ttt.select_dtypes(include=['int32']).copy()\n",
+ "y = ttt[\"class\"]\n",
+ "\n",
+ "std = preprocessing.StandardScaler()\n",
+ "x = std.fit_transform(x)\n",
+ "x"
]
},
{
@@ -60,11 +595,59 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 11,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Iteration 1, loss = 0.66454708\n",
+ "Iteration 2, loss = 0.60374428\n",
+ "Iteration 3, loss = 0.56312898\n",
+ "Iteration 4, loss = 0.56961265\n",
+ "Iteration 5, loss = 0.42101110\n",
+ "Iteration 6, loss = 0.77979335\n",
+ "Iteration 7, loss = 0.51294126\n",
+ "Iteration 8, loss = 0.44993973\n",
+ "Iteration 9, loss = 0.34721031\n",
+ "Iteration 10, loss = 0.36197357\n",
+ "Iteration 11, loss = 0.34105566\n",
+ "Iteration 12, loss = 0.20288469\n",
+ "Iteration 13, loss = 0.12470513\n",
+ "Iteration 14, loss = 0.05519443\n",
+ "Iteration 15, loss = 0.01681403\n",
+ "Iteration 16, loss = 0.00545130\n",
+ "Iteration 17, loss = 0.00207817\n",
+ "Iteration 18, loss = 0.00091740\n",
+ "Iteration 19, loss = 0.00059823\n",
+ "Iteration 20, loss = 0.00045041\n",
+ "Iteration 21, loss = 0.00036881\n",
+ "Iteration 22, loss = 0.00031193\n",
+ "Iteration 23, loss = 0.00027396\n",
+ "Iteration 24, loss = 0.00025036\n",
+ "Iteration 25, loss = 0.00023153\n",
+ "Iteration 26, loss = 0.00021917\n",
+ "Iteration 27, loss = 0.00021036\n",
+ "Iteration 28, loss = 0.00020398\n",
+ "Iteration 29, loss = 0.00019854\n",
+ "Iteration 30, loss = 0.00019422\n",
+ "Iteration 31, loss = 0.00019075\n",
+ "Training loss did not improve more than tol=0.000100 for 10 consecutive epochs. Stopping.\n",
+ "Training score: 1.0\n",
+ "Test score: 0.975\n"
+ ]
+ }
+ ],
"source": [
- "# your code here"
+ "# Train Test and using the MLPC as Pablo has explained is the balance btwn easy and useful\n",
+ "x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=23)\n",
+ "\n",
+ "mod = MLPClassifier(hidden_layer_sizes= (50,100,200) ,max_iter=200, alpha=1e-4, solver='sgd', verbose=10, random_state=23, learning_rate_init=.5)\n",
+ "mod = mod.fit(x_train, y_train)\n",
+ "\n",
+ "print(f\"Training score: {mod.score(x_train, y_train)}\")\n",
+ "print(f\"Test score: {mod.score(x_test, y_test)}\")"
]
},
{
@@ -78,11 +661,28 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 34,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "True 626\n",
+ "False 332\n",
+ "Name: class, dtype: int64 \n",
+ "\n",
+ " True 632\n",
+ "False 326\n",
+ "Name: preds, dtype: int64\n"
+ ]
+ }
+ ],
"source": [
- "# your code here"
+ "# Looks okay\n",
+ "preds = pd.DataFrame(mod.predict(x))\n",
+ "ttt[\"preds\"]=preds\n",
+ "print(ttt[\"class\"].value_counts(),\"\\n\\n\",ttt[\"preds\"].value_counts())"
]
},
{
@@ -144,9 +744,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.8.5"
}
},
"nbformat": 4,
- "nbformat_minor": 2
+ "nbformat_minor": 4
}
diff --git a/your-code/challenge-2.md b/your-code/challenge-2.md
deleted file mode 100644
index 9d98968..0000000
--- a/your-code/challenge-2.md
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-# Challenge 2: Tensorflow Hyperparameter Tuning
-
-## Getting Started
-
-From the lesson and Challenge 1 you should have noticed that understanding the concepts in neural network analysis such as *learning rate*, *epoch*, *optimizer*, *loss function* and so on is essential for you to optimize the neural network models you build. In this challenge you will study several learning pieces that discuss the hyperparameters in Tensorflow.
-
-**[Neural Networks: Structure](https://developers.google.com/machine-learning/crash-course/introduction-to-neural-networks/anatomy)**
-
-**[Understanding Deep Learning with TensorFlow Playground](https://medium.com/@andrewt3000/understanding-tensorflow-playground-c20cdb7a250b)**
-
-After that, complete [this exercise](https://developers.google.com/machine-learning/crash-course/introduction-to-neural-networks/playground-exercises) on tuning the Tensorflow hyperpamameters in the [Tensorflow Playground](https://playground.tensorflow.org/).
-
-Finally, using what you have learned, try tuning the hyperparameters for the spiral dataset in order to reach training and test loss <0.05 as shown in the following:
-
-
-
-After you're done, submit a screenshot of your Playground including the following information:
-
-* Epoch
-* Learning rate
-* Activation function
-* Features included
-* Hidden layers and neurons
-* Test and training loss
-
-**Do not google for the end solution!**
diff --git a/your-code/challenge-2.png b/your-code/challenge-2.png
deleted file mode 100644
index b378048..0000000
Binary files a/your-code/challenge-2.png and /dev/null differ