Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Challenge 1: Neural Networks #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,630 changes: 2,630 additions & 0 deletions your-code/challenge-1-julia.ipynb

Large diffs are not rendered by default.

333 changes: 329 additions & 4 deletions your-code/challenge-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,335 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'distutils'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/Users/julianuss/Documents/GitHub/lab-neural-networks/your-code/challenge-1.ipynb Zelle 3\u001b[0m line \u001b[0;36m7\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/julianuss/Documents/GitHub/lab-neural-networks/your-code/challenge-1.ipynb#W2sZmlsZQ%3D%3D?line=4'>5</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39msklearn\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mpreprocessing\u001b[39;00m \u001b[39mimport\u001b[39;00m StandardScaler\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/julianuss/Documents/GitHub/lab-neural-networks/your-code/challenge-1.ipynb#W2sZmlsZQ%3D%3D?line=5'>6</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39msklearn\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodel_selection\u001b[39;00m \u001b[39mimport\u001b[39;00m train_test_split\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/julianuss/Documents/GitHub/lab-neural-networks/your-code/challenge-1.ipynb#W2sZmlsZQ%3D%3D?line=6'>7</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mtensorflow\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mkeras\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mmodels\u001b[39;00m \u001b[39mimport\u001b[39;00m Sequential\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/julianuss/Documents/GitHub/lab-neural-networks/your-code/challenge-1.ipynb#W2sZmlsZQ%3D%3D?line=7'>8</a>\u001b[0m \u001b[39mfrom\u001b[39;00m \u001b[39mtensorflow\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mkeras\u001b[39;00m\u001b[39m.\u001b[39;00m\u001b[39mlayers\u001b[39;00m \u001b[39mimport\u001b[39;00m Dense\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/julianuss/Documents/GitHub/lab-neural-networks/your-code/challenge-1.ipynb#W2sZmlsZQ%3D%3D?line=9'>10</a>\u001b[0m df \u001b[39m=\u001b[39m pd\u001b[39m.\u001b[39mread_csv(\u001b[39m'\u001b[39m\u001b[39m/Users/julianuss/Documents/GitHub/lab-neural-networks/your-code/tic-tac-toe.csv\u001b[39m\u001b[39m'\u001b[39m)\n",
"File \u001b[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/tensorflow/__init__.py:30\u001b[0m\n\u001b[1;32m 15\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 16\u001b[0m \u001b[39mTop-level module of TensorFlow. By convention, we refer to this module as\u001b[39;00m\n\u001b[1;32m 17\u001b[0m \u001b[39m`tf` instead of `tensorflow`, following the common practice of importing\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[39mthis file with a file generated from [`api_template.__init__.py`](https://www.github.com/tensorflow/tensorflow/blob/master/tensorflow/api_template.__init__.py)\u001b[39;00m\n\u001b[1;32m 27\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 28\u001b[0m \u001b[39m# pylint: disable=g-bad-import-order,protected-access,g-import-not-at-top\u001b[39;00m\n\u001b[0;32m---> 30\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mdistutils\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39m_distutils\u001b[39;00m\n\u001b[1;32m 31\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mimportlib\u001b[39;00m\n\u001b[1;32m 32\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39minspect\u001b[39;00m \u001b[39mas\u001b[39;00m \u001b[39m_inspect\u001b[39;00m\n",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'distutils'"
]
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pandas as pd\n",
"import seaborn as sns\n",
"from sklearn.preprocessing import StandardScaler\n",
"from sklearn.model_selection import train_test_split\n",
"from tensorflow.keras.models import Sequential\n",
"from tensorflow.keras.layers import Dense\n",
"\n",
"df = pd.read_csv('/Users/julianuss/Documents/GitHub/lab-neural-networks/your-code/tic-tac-toe.csv')\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'pandas.core.frame.DataFrame'>\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",
"None\n",
"(958, 10)\n",
" TL TM TR ML MM MR BL BM BR class\n",
"count 958 958 958 958 958 958 958 958 958 958\n",
"unique 3 3 3 3 3 3 3 3 3 2\n",
"top x x x x x x x x x True\n",
"freq 418 378 418 378 458 378 418 378 418 626\n",
"Index(['TL', 'TM', 'TR', 'ML', 'MM', 'MR', 'BL', 'BM', 'BR', 'class'], dtype='object')\n"
]
}
],
"source": [
"# Looking into the basic details of the DataFrame\n",
"print(df.info())\n",
"print(df.shape)\n",
"print(df.describe())\n",
"print(df.columns)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>class</th>\n",
" <th>TL_o</th>\n",
" <th>TL_x</th>\n",
" <th>TM_o</th>\n",
" <th>TM_x</th>\n",
" <th>TR_o</th>\n",
" <th>TR_x</th>\n",
" <th>ML_o</th>\n",
" <th>ML_x</th>\n",
" <th>MM_o</th>\n",
" <th>MM_x</th>\n",
" <th>MR_o</th>\n",
" <th>MR_x</th>\n",
" <th>BL_o</th>\n",
" <th>BL_x</th>\n",
" <th>BM_o</th>\n",
" <th>BM_x</th>\n",
" <th>BR_o</th>\n",
" <th>BR_x</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>True</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" <td>False</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" class TL_o TL_x TM_o TM_x TR_o TR_x ML_o ML_x MM_o MM_x \\\n",
"0 True False True False True False True False True True False \n",
"1 True False True False True False True False True True False \n",
"2 True False True False True False True False True True False \n",
"3 True False True False True False True False True True False \n",
"4 True False True False True False True False True True False \n",
"\n",
" MR_o MR_x BL_o BL_x BM_o BM_x BR_o BR_x \n",
"0 True False False True True False True False \n",
"1 True False True False False True True False \n",
"2 True False True False True False False True \n",
"3 True False True False False False False False \n",
"4 True False False False True False False False "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# One-hot-encoding\n",
"df = pd.get_dummies(df, drop_first=True)\n",
"df.head()\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# Seperating input and output\n",
"X = df.iloc[:, :-1] \n",
"y = df.iloc[:, -1]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Normalized Input Data:\n",
" class TL_o TL_x TM_o TM_x TR_o TR_x \\\n",
"0 0.728252 -0.733294 1.136603 -0.724898 1.238706 -0.733294 1.136603 \n",
"1 0.728252 -0.733294 1.136603 -0.724898 1.238706 -0.733294 1.136603 \n",
"2 0.728252 -0.733294 1.136603 -0.724898 1.238706 -0.733294 1.136603 \n",
"3 0.728252 -0.733294 1.136603 -0.724898 1.238706 -0.733294 1.136603 \n",
"4 0.728252 -0.733294 1.136603 -0.724898 1.238706 -0.733294 1.136603 \n",
"\n",
" ML_o ML_x MM_o MM_x MR_o MR_x BL_o \\\n",
"0 -0.724898 1.238706 1.348201 -0.957079 1.379504 -0.807294 -0.733294 \n",
"1 -0.724898 1.238706 1.348201 -0.957079 1.379504 -0.807294 1.363709 \n",
"2 -0.724898 1.238706 1.348201 -0.957079 1.379504 -0.807294 1.363709 \n",
"3 -0.724898 1.238706 1.348201 -0.957079 1.379504 -0.807294 1.363709 \n",
"4 -0.724898 1.238706 1.348201 -0.957079 1.379504 -0.807294 -0.733294 \n",
"\n",
" BL_x BM_o BM_x BR_o \n",
"0 1.136603 1.379504 -0.807294 1.363709 \n",
"1 -0.879815 -0.724898 1.238706 1.363709 \n",
"2 -0.879815 1.379504 -0.807294 -0.733294 \n",
"3 -0.879815 -0.724898 -0.807294 -0.733294 \n",
"4 -0.879815 1.379504 -0.807294 -0.733294 \n",
"\n",
"Output:\n",
"0 False\n",
"1 False\n",
"2 True\n",
"3 False\n",
"4 False\n",
"Name: BR_x, dtype: bool\n"
]
}
],
"source": [
"scaler = StandardScaler()\n",
"X_normalized = scaler.fit_transform(X)\n",
"\n",
"# Convert back to a DataFrame if needed\n",
"X_normalized_df = pd.DataFrame(X_normalized, columns=X.columns)\n",
"\n",
"# Display the normalized input data and the target data\n",
"print(\"Normalized Input Data:\")\n",
"print(X_normalized_df.head())\n",
"\n",
"print(\"\\nOutput:\")\n",
"print(y.head())"
]
},
{
Expand All @@ -64,7 +388,8 @@
"metadata": {},
"outputs": [],
"source": [
"# your code here"
"# Splitting the data\n",
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)"
]
},
{
Expand Down Expand Up @@ -144,7 +469,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
Binary file not shown.
Binary file added your-code/refined-tic-tac-toe-model-v2.keras
Binary file not shown.
Binary file added your-code/refined-tic-tac-toe-model.keras
Binary file not shown.
Binary file added your-code/simplified-tic-tac-toe-model.keras
Binary file not shown.
Binary file added your-code/tic-tac-toe-improved-model.keras
Binary file not shown.
Binary file added your-code/tic-tac-toe-regularized-model.keras
Binary file not shown.
Binary file added your-code/tic-tac-toe.keras
Binary file not shown.