{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-09-12T05:54:22.998877Z","iopub.execute_input":"2022-09-12T05:54:22.999325Z","iopub.status.idle":"2022-09-12T05:54:23.024760Z","shell.execute_reply.started":"2022-09-12T05:54:22.999288Z","shell.execute_reply":"2022-09-12T05:54:23.023876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\nimport numpy as np\nimport pandas as pd \nimport matplotlib\nimport matplotlib.pyplot as plt\nfrom sklearn.manifold import TSNE","metadata":{"execution":{"iopub.status.busy":"2022-09-12T05:54:23.030949Z","iopub.execute_input":"2022-09-12T05:54:23.031513Z","iopub.status.idle":"2022-09-12T05:54:23.036263Z","shell.execute_reply.started":"2022-09-12T05:54:23.031471Z","shell.execute_reply":"2022-09-12T05:54:23.035178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Parse the training data into a numpy array :``` data_array``` size = (len(data), len(features) )","metadata":{}},{"cell_type":"code","source":"df = pd.read_json('../input/ai-village-ctf/murderbots/train_data.json')\ndata_array = df.to_numpy(dtype=\"float32\")\ndata_array_mean = np.mean(data_array,axis = 0,keepdims = True)\ndata_array_std = np.std(data_array,axis = 0,keepdims = True)\ndata_array -= data_array_mean\ndata_array /= data_array_std\ndata_array.shape","metadata":{"execution":{"iopub.status.busy":"2022-09-12T05:54:23.044410Z","iopub.execute_input":"2022-09-12T05:54:23.045617Z","iopub.status.idle":"2022-09-12T05:54:23.066857Z","shell.execute_reply.started":"2022-09-12T05:54:23.045556Z","shell.execute_reply":"2022-09-12T05:54:23.065695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Parse the training label into a numpy array :``` label_array``` size = (len(data),)","metadata":{}},{"cell_type":"code","source":"dflabel = pd.read_json('../input/ai-village-ctf/murderbots/train_labels.json')\ndflabel = dflabel.sort_index()\nlabel_array = dflabel.to_numpy()\ndflabel.shape","metadata":{"execution":{"iopub.status.busy":"2022-09-12T05:54:23.068559Z","iopub.execute_input":"2022-09-12T05:54:23.068988Z","iopub.status.idle":"2022-09-12T05:54:23.091819Z","shell.execute_reply.started":"2022-09-12T05:54:23.068958Z","shell.execute_reply":"2022-09-12T05:54:23.090508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Parse the testing data into a numpy array :``` testdata_array``` size = (len(testdata), len(features) )","metadata":{}},{"cell_type":"code","source":"df2 = pd.read_json('../input/ai-village-ctf/murderbots/test_data.json')\ntestdata_array = df2.to_numpy(dtype=\"float32\")\ntestdata_array -= data_array_mean\ntestdata_array /= data_array_std\ntestdata_array.shape","metadata":{"execution":{"iopub.status.busy":"2022-09-12T05:54:23.092739Z","iopub.status.idle":"2022-09-12T05:54:23.093613Z","shell.execute_reply.started":"2022-09-12T05:54:23.093392Z","shell.execute_reply":"2022-09-12T05:54:23.093414Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Run TSNE","metadata":{}},{"cell_type":"code","source":"arr = np.concatenate((data_array,testdata_array), axis=0)\nX_embedded = TSNE(n_components=2, learning_rate='auto',init='random', perplexity=5).fit_transform(arr)","metadata":{"execution":{"iopub.status.busy":"2022-09-12T05:54:23.094721Z","iopub.status.idle":"2022-09-12T05:54:23.095330Z","shell.execute_reply.started":"2022-09-12T05:54:23.095132Z","shell.execute_reply":"2022-09-12T05:54:23.095153Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plot the results Blue=\"human\", Red=\"not human\", Number=\"testing data\"","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize = (20,16))\nfor i,point in enumerate(X_embedded[:len(data_array)]):\n\tif label_array[i]:\n\t\tplt.scatter(point[0],point[1],color = \"blue\")\nfor i,point in enumerate(X_embedded[:len(data_array)]):\n\tif not label_array[i]:\n\t\tplt.scatter(point[0],point[1],color = \"red\")\nfor i,point in enumerate(X_embedded[len(data_array):]):\n\t#plt.scatter(point[0],point[1],color = \"green\")\n\tplt.text(point[0],point[1],str(i))\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-09-12T05:54:23.096414Z","iopub.status.idle":"2022-09-12T05:54:23.097029Z","shell.execute_reply.started":"2022-09-12T05:54:23.096798Z","shell.execute_reply":"2022-09-12T05:54:23.096842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Find test data that is close to human training data ","metadata":{}},{"cell_type":"code","source":"solution = [16,40,38,13,34,30,12,22,21,36]\nsolution_str = \"\"\nfor i in range(50):\n\tif i in solution:\n\t\tsolution_str += \"1\"\n\telse:\n\t\tsolution_str += \"0\"\nsolution_str","metadata":{"execution":{"iopub.status.busy":"2022-09-12T05:54:23.185474Z","iopub.execute_input":"2022-09-12T05:54:23.186139Z","iopub.status.idle":"2022-09-12T05:54:23.193060Z","shell.execute_reply.started":"2022-09-12T05:54:23.186103Z","shell.execute_reply":"2022-09-12T05:54:23.192179Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import requests\n\ntry:\n    r = requests.post(\"http://murderbot.fly.dev:5000/score\", json=json.dumps({\"submission\": solution_str, 'challenge_id':'murderbots'}))\n    print(r.text)\nexcept requests.exceptions.ConnectionError:\n    print(\"Connection problems. Contact the CTF organizers.\")","metadata":{"execution":{"iopub.status.busy":"2022-09-12T05:54:23.194667Z","iopub.execute_input":"2022-09-12T05:54:23.195229Z","iopub.status.idle":"2022-09-12T05:54:23.318918Z","shell.execute_reply.started":"2022-09-12T05:54:23.195197Z","shell.execute_reply":"2022-09-12T05:54:23.317760Z"},"trusted":true},"execution_count":null,"outputs":[]}]}