{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Analytics\n",
"Your first model just randomly places ships of size 2. Since you can make ships of many different shapes we would like to find what is the best shape. You also need to change the shape of your ships since other teams shooting models will learn the patterns of your layout. In this model, each game your model will choose one of two different layout strategies and you will then use [Amazon Athena](https://aws.amazon.com/athena/) to see the results. You can then repeat the experiment with new ship sizes and shapes to see if you can find better strategies. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code \n",
"The code for your second model is in /containers/Layout/2vs3 and contains the following files\n",
" \n",
"- ### /containers/Layout/2vs3/Makefile\n",
"Makefile for creating the tar.gz file of code for [Amazon Sagemaker](https://aws.amazon.com/sagemaker/) framework containers\n",
"\n",
"- ### [/containers/Layout/2vs3/host.py](/edit/GameDayRepo/containers/Layout/2vs3/host.py)\n",
"The code for generating inferences. In addition to randomly selecting a layout strategy it will also put a tag in the session attribute that we will use in athena to compare different games. You can change the tag value (which you should do for each model) by editing the host.py file. (don't run this file directly, use test.py)\n",
"\n",
"- ### [/containers/Layout/2vs3/test.py](/edit/GameDayRepo/containers/Layout/2vs3/test.py)\n",
"code for testing the the host.py and train.py files locally. It creates a mock [Amazon Sagemaker](https://aws.amazon.com/sagemaker/) runtime inorder to run train.py and then test.py. You can edit this file inorder to customize your test. if you get a message about missing dependencies (like mxnet) just install them with:\n",
"```shell\n",
"pip install mxnet # for example\n",
"```\n",
"\n",
"- ### [/containers/Layout/2vs3/train.py](/edit/GameDayRepo/containers/Layout/2vs3/train.py)\n",
"the training code (don't run this file directly, use test.py)\n",
"\n",
"\n",
" Next, run the test script locally to confirm the scripts works. \n",
"```shell\n",
"python ./test.py\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configure\n",
"Before you can deploy your second model you need to configure the deployment. As described in the [Endpoint Notebook](../Endpoint_Reference.ipynb), you will edit to the deployment configuration in [/layout-config.json](/edit/GameDayRepo/layout-config.json). you need to edit the following field to the following values\n",
"\n",
"|parameter field|Value|\n",
"|---|---|\n",
"|trainsourcefile|`layout-2vs3.tar.gz`|\n",
"|hostsourcefile|`layout-2vs3.tar.gz`|\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Deploy\n",
"1. follow instructions from endpoint reference to commit your code and changes and then push your changes to the remote branch\n",
"2. tell operations to deploy your changes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Next Steps\n",
"Next, monitor you models performance. see [Athena](../Athena.ipynb) for details on setting up Athena (replace values between `<>` like in the Athena instructions). The following query will show win percentage by ship size (2 or 3). \n",
"```sql\n",
"SELECT type,\n",
" sum(won)/(sum(won)+sum(lost)) as won,\n",
" sum(lost)/(sum(won)+sum(lost)) as lost\n",
"FROM \n",
" (SELECT json_extract(session,'$.size') AS size,\n",
" CASE\n",
" WHEN winner = '' THEN 1.0\n",
" ELSE 0.0\n",
" END AS won,\n",
" CASE\n",
" WHEN winner != '' THEN 1.0\n",
" ELSE 0.0\n",
" END AS lost\n",
" FROM \n",
" (SELECT teama.session AS session,\n",
" teama.teamname AS team,\n",
" winner\n",
" FROM \"\".\"\"\n",
" UNION\n",
" SELECT teamb.session AS session,\n",
" teamb.teamname AS team,\n",
" winner\n",
" FROM \"\".\"\" )\n",
" WHERE team = '' )\n",
" GROUP BY size\n",
"``` \n",
"Now program some new ship sizes or shapes to do another round of experiments with, deploy it out, and rerun your athena query to see performance"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "conda_python3",
"language": "python",
"name": "conda_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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}