{"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","editable":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfOG = pd.read_csv('/kaggle/input/2022-ucs757-lab-1-exam/train.csv')\n# dfOG.head()\n# testOG = pd.read_csv('/kaggle/input/2022-ucs757-lab-1-exam/test.csv', sep='\\t', encoding='utf-8')\nwith open('/kaggle/input/2022-ucs757-lab-1-exam/test.csv', encoding=\"utf16\", errors='ignore') as f:\n# with open('/kaggle/input/2022-ucs757-lab-1-exam/test.csv', 'rb') as f:\n    testOG = pd.read_csv(f, encoding=\"utf8\", sep='\\t')\n#     contents = f.read()\n\n# testOG = pd.read_csv(contents')\n# testOG.head()\nprint(dfOG.loc[dfOG['target']==1])","metadata":{"editable":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# print(df.columns)\ndf = dfOG.copy(deep=True)\ntest = testOG.copy(deep=True)\ntest = test.loc[:,test.columns[1:]]\ny = df.loc[:,df.columns[1]]\ndf = df.loc[:,df.columns[2:]]\nprint(df.head(), y, test.head())\n\n","metadata":{"editable":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x = np.array(df)\ny = np.array(y)\ntest_x = np.array(test)\nprint(x.shape, y, test_x.shape)\nx=x/4\ntest_x=test_x/4","metadata":{"editable":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras\n\nmodel=tf.keras.Sequential([\n    keras.layers.InputLayer(input_shape=x.shape),\n    keras.layers.Conv1D(filters=32, kernel_size = 5, strides=21,activation='relu', padding=\"casual\"), #21,42,50,25\n  keras.layers.Dense(64,activation='relu'),\n    keras.layers.Dense(32,activation='relu'),\n    keras.layers.Dropout(0.2),\n    keras.layers.Dense(8,activation='relu'),\n    keras.layers.Dropout(0.3),\n    keras.layers.Dense(1,activation='sigmoid')\n])\n\nmodel.compile(loss='binary_crossentropy',optimizer='adam', metrics=['accuracy'])\nmodel.summary()","metadata":{"editable":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"hist = model.fit(x,y,epochs=200)","metadata":{"editable":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"preds = model.predict(test_x)\npreds=preds.round().astype(int)\nprint(type(preds))","metadata":{"execution":{"iopub.status.busy":"2022-12-08T14:26:02.554025Z","iopub.execute_input":"2022-12-08T14:26:02.554380Z","iopub.status.idle":"2022-12-08T14:26:02.721140Z","shell.execute_reply.started":"2022-12-08T14:26:02.554351Z","shell.execute_reply":"2022-12-08T14:26:02.720019Z"},"editable":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ctr=0\nfor index, row in dfOG.iterrows():\n#     print(row)\n    if row['target']==0:\n        ctr+=1\nprint(ctr)","metadata":{"execution":{"iopub.status.busy":"2022-12-08T14:05:39.835559Z","iopub.execute_input":"2022-12-08T14:05:39.835976Z","iopub.status.idle":"2022-12-08T14:05:40.310980Z","shell.execute_reply.started":"2022-12-08T14:05:39.835940Z","shell.execute_reply":"2022-12-08T14:05:40.309947Z"},"editable":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ctr=0\nfor c in preds:\n    if c==1:\n        ctr+=1\nprint(ctr)","metadata":{"execution":{"iopub.status.busy":"2022-12-08T14:26:10.350741Z","iopub.execute_input":"2022-12-08T14:26:10.351432Z","iopub.status.idle":"2022-12-08T14:26:10.359803Z","shell.execute_reply.started":"2022-12-08T14:26:10.351396Z","shell.execute_reply":"2022-12-08T14:26:10.358829Z"},"editable":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output = testOG[['id']]\noutput = output.assign(target = preds)\noutput\n","metadata":{"execution":{"iopub.status.busy":"2022-12-08T14:26:12.781204Z","iopub.execute_input":"2022-12-08T14:26:12.781568Z","iopub.status.idle":"2022-12-08T14:26:12.796492Z","shell.execute_reply.started":"2022-12-08T14:26:12.781536Z","shell.execute_reply":"2022-12-08T14:26:12.795396Z"},"editable":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"output.to_csv(\"abcd.csv\", index=False)","metadata":{"execution":{"iopub.status.busy":"2022-12-08T14:26:24.203601Z","iopub.execute_input":"2022-12-08T14:26:24.203984Z","iopub.status.idle":"2022-12-08T14:26:24.214691Z","shell.execute_reply.started":"2022-12-08T14:26:24.203953Z","shell.execute_reply":"2022-12-08T14:26:24.213702Z"},"editable":false,"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"editable":false},"execution_count":null,"outputs":[]}]}