{"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-10-10T06:27:31.192484Z","iopub.execute_input":"2022-10-10T06:27:31.193153Z","iopub.status.idle":"2022-10-10T06:27:31.202794Z","shell.execute_reply.started":"2022-10-10T06:27:31.193111Z","shell.execute_reply":"2022-10-10T06:27:31.201909Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dtypes_df = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_dtypes.csv')\ndtypes = {k: v for (k, v) in zip(dtypes_df.column, dtypes_df.dtype)}\ndf1 = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_0.csv',dtype=dtypes)\ndf2 = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_1.csv',dtype=dtypes)\ndf3 = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_2.csv',dtype=dtypes)\ndf4 = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_3.csv',dtype=dtypes)\ndf5 = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_4.csv',dtype=dtypes)\ndf6 = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/train_5.csv',dtype=dtypes)","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:27:31.863354Z","iopub.execute_input":"2022-10-10T06:27:31.863659Z","iopub.status.idle":"2022-10-10T06:30:15.505324Z","shell.execute_reply.started":"2022-10-10T06:27:31.863628Z","shell.execute_reply":"2022-10-10T06:30:15.504260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.concat([df1,df2,df3,df4,df5,df6])","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:30:15.507347Z","iopub.execute_input":"2022-10-10T06:30:15.507611Z","iopub.status.idle":"2022-10-10T06:30:18.081143Z","shell.execute_reply.started":"2022-10-10T06:30:15.507580Z","shell.execute_reply":"2022-10-10T06:30:18.079970Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del df1,df2,df3,df4,df5,df6","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:30:18.082627Z","iopub.execute_input":"2022-10-10T06:30:18.083074Z","iopub.status.idle":"2022-10-10T06:30:18.144008Z","shell.execute_reply.started":"2022-10-10T06:30:18.083030Z","shell.execute_reply":"2022-10-10T06:30:18.143087Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dft = pd.read_csv('/kaggle/input/tabular-playground-series-oct-2022/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:30:18.146658Z","iopub.execute_input":"2022-10-10T06:30:18.147005Z","iopub.status.idle":"2022-10-10T06:30:26.702929Z","shell.execute_reply.started":"2022-10-10T06:30:18.146959Z","shell.execute_reply":"2022-10-10T06:30:26.701897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df= df.dropna()\ndf.shape","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:30:26.704535Z","iopub.execute_input":"2022-10-10T06:30:26.704844Z","iopub.status.idle":"2022-10-10T06:30:34.303728Z","shell.execute_reply.started":"2022-10-10T06:30:26.704804Z","shell.execute_reply":"2022-10-10T06:30:34.303009Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainXA = df[['ball_pos_x', 'ball_pos_y', 'ball_pos_z', 'ball_vel_x',\n       'ball_vel_y', 'ball_vel_z', 'p0_pos_x', 'p0_pos_y', 'p0_pos_z',\n       'p0_vel_x', 'p0_vel_y', 'p0_vel_z', 'p0_boost', 'p1_pos_x', 'p1_pos_y',\n       'p1_pos_z', 'p1_vel_x', 'p1_vel_y', 'p1_vel_z', 'p1_boost', 'p2_pos_x',\n       'p2_pos_y', 'p2_pos_z', 'p2_vel_x', 'p2_vel_y', 'p2_vel_z', 'p2_boost',\n       'p3_pos_x', 'p3_pos_y', 'p3_pos_z', 'p3_vel_x', 'p3_vel_y', 'p3_vel_z',\n       'p3_boost', 'p4_pos_x', 'p4_pos_y', 'p4_pos_z', 'p4_vel_x', 'p4_vel_y',\n       'p4_vel_z', 'p4_boost', 'p5_pos_x', 'p5_pos_y', 'p5_pos_z', 'p5_vel_x',\n       'p5_vel_y', 'p5_vel_z', 'p5_boost', 'boost0_timer', 'boost1_timer',\n       'boost2_timer', 'boost3_timer', 'boost4_timer', 'boost5_timer']]\ntrainYA = df[['team_A_scoring_within_10sec']]","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:30:34.305037Z","iopub.execute_input":"2022-10-10T06:30:34.305903Z","iopub.status.idle":"2022-10-10T06:30:35.496417Z","shell.execute_reply.started":"2022-10-10T06:30:34.305852Z","shell.execute_reply":"2022-10-10T06:30:35.495471Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainXB = df[['ball_pos_x', 'ball_pos_y', 'ball_pos_z', 'ball_vel_x',\n       'ball_vel_y', 'ball_vel_z', 'p0_pos_x', 'p0_pos_y', 'p0_pos_z',\n       'p0_vel_x', 'p0_vel_y', 'p0_vel_z', 'p0_boost', 'p1_pos_x', 'p1_pos_y',\n       'p1_pos_z', 'p1_vel_x', 'p1_vel_y', 'p1_vel_z', 'p1_boost', 'p2_pos_x',\n       'p2_pos_y', 'p2_pos_z', 'p2_vel_x', 'p2_vel_y', 'p2_vel_z', 'p2_boost',\n       'p3_pos_x', 'p3_pos_y', 'p3_pos_z', 'p3_vel_x', 'p3_vel_y', 'p3_vel_z',\n       'p3_boost', 'p4_pos_x', 'p4_pos_y', 'p4_pos_z', 'p4_vel_x', 'p4_vel_y',\n       'p4_vel_z', 'p4_boost', 'p5_pos_x', 'p5_pos_y', 'p5_pos_z', 'p5_vel_x',\n       'p5_vel_y', 'p5_vel_z', 'p5_boost', 'boost0_timer', 'boost1_timer',\n       'boost2_timer', 'boost3_timer', 'boost4_timer', 'boost5_timer']]\n\ntrainYB = df[['team_B_scoring_within_10sec']]","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:30:35.497441Z","iopub.execute_input":"2022-10-10T06:30:35.498218Z","iopub.status.idle":"2022-10-10T06:30:36.678247Z","shell.execute_reply.started":"2022-10-10T06:30:35.498188Z","shell.execute_reply":"2022-10-10T06:30:36.677192Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = dft[['ball_pos_x', 'ball_pos_y', 'ball_pos_z', 'ball_vel_x',\n       'ball_vel_y', 'ball_vel_z', 'p0_pos_x', 'p0_pos_y', 'p0_pos_z',\n       'p0_vel_x', 'p0_vel_y', 'p0_vel_z', 'p0_boost', 'p1_pos_x', 'p1_pos_y',\n       'p1_pos_z', 'p1_vel_x', 'p1_vel_y', 'p1_vel_z', 'p1_boost', 'p2_pos_x',\n       'p2_pos_y', 'p2_pos_z', 'p2_vel_x', 'p2_vel_y', 'p2_vel_z', 'p2_boost',\n       'p3_pos_x', 'p3_pos_y', 'p3_pos_z', 'p3_vel_x', 'p3_vel_y', 'p3_vel_z',\n       'p3_boost', 'p4_pos_x', 'p4_pos_y', 'p4_pos_z', 'p4_vel_x', 'p4_vel_y',\n       'p4_vel_z', 'p4_boost', 'p5_pos_x', 'p5_pos_y', 'p5_pos_z', 'p5_vel_x',\n       'p5_vel_y', 'p5_vel_z', 'p5_boost', 'boost0_timer', 'boost1_timer',\n       'boost2_timer', 'boost3_timer', 'boost4_timer', 'boost5_timer']]","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:30:36.679586Z","iopub.execute_input":"2022-10-10T06:30:36.679839Z","iopub.status.idle":"2022-10-10T06:30:36.779794Z","shell.execute_reply.started":"2022-10-10T06:30:36.679809Z","shell.execute_reply":"2022-10-10T06:30:36.778604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test.fillna(test.mean(), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:30:36.781250Z","iopub.execute_input":"2022-10-10T06:30:36.781951Z","iopub.status.idle":"2022-10-10T06:30:36.935199Z","shell.execute_reply.started":"2022-10-10T06:30:36.781905Z","shell.execute_reply":"2022-10-10T06:30:36.934425Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del df,dft","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:30:36.938134Z","iopub.execute_input":"2022-10-10T06:30:36.938715Z","iopub.status.idle":"2022-10-10T06:30:36.992550Z","shell.execute_reply.started":"2022-10-10T06:30:36.938666Z","shell.execute_reply":"2022-10-10T06:30:36.991657Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense\nfrom sklearn.preprocessing import StandardScaler\nscaler = StandardScaler()\ntrainXA = scaler.fit_transform(trainXA)\ntrainXB = scaler.fit_transform(trainXB)\ntest = scaler.fit_transform(test)","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:30:36.994128Z","iopub.execute_input":"2022-10-10T06:30:36.994742Z","iopub.status.idle":"2022-10-10T06:31:00.167404Z","shell.execute_reply.started":"2022-10-10T06:30:36.994697Z","shell.execute_reply":"2022-10-10T06:31:00.166611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainXA = pd.DataFrame(trainXA)\ntrainXB = pd.DataFrame(trainXB)\ntest = pd.DataFrame(test)","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:31:00.168612Z","iopub.execute_input":"2022-10-10T06:31:00.169117Z","iopub.status.idle":"2022-10-10T06:31:00.174033Z","shell.execute_reply.started":"2022-10-10T06:31:00.169070Z","shell.execute_reply":"2022-10-10T06:31:00.173195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainXA.shape","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:31:00.175361Z","iopub.execute_input":"2022-10-10T06:31:00.175718Z","iopub.status.idle":"2022-10-10T06:31:00.189490Z","shell.execute_reply.started":"2022-10-10T06:31:00.175690Z","shell.execute_reply":"2022-10-10T06:31:00.188630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\ntpu = tf.distribute.cluster_resolver.TPUClusterResolver.connect()\n\n# instantiate a distribution strategy\ntpu_strategy = tf.distribute.experimental.TPUStrategy(tpu)\n\n# instantiating the model in the strategy scope creates the model on the TPU\nwith tpu_strategy.scope():\n    modelA = Sequential()\n    modelA.add(Dense(256, input_shape=(54,), activation='relu'))\n    modelA.add(Dense(128,activation='relu'))\n    modelA.add(Dense(64,activation='relu'))\n    modelA.add(Dense(1, activation='sigmoid'))\n    modelA.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n    modelA.fit(trainXA,trainYA,epochs=50, steps_per_epoch=4)","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:35:12.374068Z","iopub.execute_input":"2022-10-10T06:35:12.374430Z","iopub.status.idle":"2022-10-10T06:36:34.395126Z","shell.execute_reply.started":"2022-10-10T06:35:12.374397Z","shell.execute_reply":"2022-10-10T06:36:34.393957Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"BATCH_SIZE = 16 * tpu_strategy.num_replicas_in_sync\nBATCH_SIZE","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:13:15.893796Z","iopub.execute_input":"2022-10-10T06:13:15.894165Z","iopub.status.idle":"2022-10-10T06:13:15.900298Z","shell.execute_reply.started":"2022-10-10T06:13:15.894129Z","shell.execute_reply":"2022-10-10T06:13:15.899284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with tpu_strategy.scope():\n    modelB = Sequential()\n    modelB.add(Dense(64, input_shape=(54,), activation='relu'))\n    modelB.add(Dense(1, activation='sigmoid'))\n    modelB.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])\n    modelB.fit(trainXB,trainYB,epochs=50, steps_per_epoch=4)","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:36:45.641805Z","iopub.execute_input":"2022-10-10T06:36:45.642234Z","iopub.status.idle":"2022-10-10T06:38:04.115981Z","shell.execute_reply.started":"2022-10-10T06:36:45.642193Z","shell.execute_reply":"2022-10-10T06:38:04.114900Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"with tpu_strategy.scope():\n    A = modelA.predict(test)\n    B = modelB.predict(test)","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:38:13.771286Z","iopub.execute_input":"2022-10-10T06:38:13.771645Z","iopub.status.idle":"2022-10-10T06:41:08.350035Z","shell.execute_reply.started":"2022-10-10T06:38:13.771609Z","shell.execute_reply":"2022-10-10T06:41:08.348630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"A = [int(a>0.5) for a in A]\nB = [int(a>0.5) for a in B]","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:41:14.366470Z","iopub.execute_input":"2022-10-10T06:41:14.366822Z","iopub.status.idle":"2022-10-10T06:41:16.528238Z","shell.execute_reply.started":"2022-10-10T06:41:14.366784Z","shell.execute_reply":"2022-10-10T06:41:16.527253Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ss = pd.read_csv('../input/tabular-playground-series-oct-2022/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:41:16.530332Z","iopub.execute_input":"2022-10-10T06:41:16.531129Z","iopub.status.idle":"2022-10-10T06:41:16.730101Z","shell.execute_reply.started":"2022-10-10T06:41:16.531080Z","shell.execute_reply":"2022-10-10T06:41:16.729205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.DataFrame({'id':ss.id,'team_A_scoring_within_10sec':A,'team_B_scoring_within_10sec':B})","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:41:16.731446Z","iopub.execute_input":"2022-10-10T06:41:16.731987Z","iopub.status.idle":"2022-10-10T06:41:17.092120Z","shell.execute_reply.started":"2022-10-10T06:41:16.731942Z","shell.execute_reply":"2022-10-10T06:41:17.091061Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.to_csv('SS6.csv',index = False)","metadata":{"execution":{"iopub.status.busy":"2022-10-10T06:41:22.833850Z","iopub.execute_input":"2022-10-10T06:41:22.834490Z","iopub.status.idle":"2022-10-10T06:41:23.735320Z","shell.execute_reply.started":"2022-10-10T06:41:22.834432Z","shell.execute_reply":"2022-10-10T06:41:23.734323Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}