{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":84896,"databundleVersionId":10305135,"sourceType":"competition"}],"dockerImageVersionId":30804,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"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","trusted":true,"execution":{"iopub.status.busy":"2024-12-28T20:01:29.853698Z","iopub.status.idle":"2024-12-28T20:01:29.854019Z","shell.execute_reply.started":"2024-12-28T20:01:29.853861Z","shell.execute_reply":"2024-12-28T20:01:29.853889Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import category_encoders as ce\nencoder = ce.TargetEncoder()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T20:01:29.85552Z","iopub.status.idle":"2024-12-28T20:01:29.855831Z","shell.execute_reply.started":"2024-12-28T20:01:29.855681Z","shell.execute_reply":"2024-12-28T20:01:29.855702Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test = pd.read_csv('/kaggle/input/playground-series-s4e12/test.csv')\ntrain = pd.read_csv('/kaggle/input/playground-series-s4e12/train.csv')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T20:01:29.856933Z","iopub.status.idle":"2024-12-28T20:01:29.857261Z","shell.execute_reply.started":"2024-12-28T20:01:29.857108Z","shell.execute_reply":"2024-12-28T20:01:29.857125Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.info()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T20:01:29.858578Z","iopub.status.idle":"2024-12-28T20:01:29.858881Z","shell.execute_reply.started":"2024-12-28T20:01:29.858736Z","shell.execute_reply":"2024-12-28T20:01:29.858755Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train[train.select_dtypes(['object']).columns] = encoder.fit_transform(train[train.select_dtypes(['object']).columns], train['Premium Amount'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T20:01:29.859973Z","iopub.status.idle":"2024-12-28T20:01:29.860331Z","shell.execute_reply.started":"2024-12-28T20:01:29.860181Z","shell.execute_reply":"2024-12-28T20:01:29.860198Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train.corr()['Premium Amount']","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T20:01:29.861287Z","iopub.status.idle":"2024-12-28T20:01:29.861589Z","shell.execute_reply.started":"2024-12-28T20:01:29.861447Z","shell.execute_reply":"2024-12-28T20:01:29.861466Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test[test.select_dtypes(['object']).columns] = encoder.transform(test[test.select_dtypes(['object']).columns])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T20:01:29.862707Z","iopub.status.idle":"2024-12-28T20:01:29.862995Z","shell.execute_reply.started":"2024-12-28T20:01:29.862854Z","shell.execute_reply":"2024-12-28T20:01:29.862873Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"x_train = train.fillna(train.median()).drop(columns=['Premium Amount','id'])\ny_train = train['Premium Amount']\nx_test = test.fillna(test.median()).drop(columns=['id'])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-28T20:01:29.863949Z","iopub.status.idle":"2024-12-28T20:01:29.864269Z","shell.execute_reply.started":"2024-12-28T20:01:29.864121Z","shell.execute_reply":"2024-12-28T20:01:29.864137Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import tensorflow as tf \nfrom tensorflow.keras.models import Sequential \nfrom tensorflow.keras.layers import Dense, Dropout, BatchNormalization","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-22T14:42:04.123734Z","iopub.execute_input":"2024-12-22T14:42:04.124059Z","iopub.status.idle":"2024-12-22T14:42:04.128268Z","shell.execute_reply.started":"2024-12-22T14:42:04.124034Z","shell.execute_reply":"2024-12-22T14:42:04.127326Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\nmodel = Sequential()\nmodel.add(Dense(512, activation='relu', input_shape=(19,)))\nmodel.add(BatchNormalization())\nmodel.add(Dropout(0.3))\n\nmodel.add(Dense(256, activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(Dropout(0.3))\n\nmodel.add(Dense(128, activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(Dropout(0.3))\n\nmodel.add(Dense(64, activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(Dropout(0.3))\n\nmodel.add(Dense(32, activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(Dropout(0.3))\n\nmodel.add(Dense(16, activation='relu'))\nmodel.add(BatchNormalization())\nmodel.add(Dropout(0.3))\n\nmodel.add(Dense(1))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-22T14:42:23.150748Z","iopub.execute_input":"2024-12-22T14:42:23.151702Z","iopub.status.idle":"2024-12-22T14:42:23.341413Z","shell.execute_reply.started":"2024-12-22T14:42:23.151665Z","shell.execute_reply":"2024-12-22T14:42:23.340546Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.compile(optimizer='adam', loss='mean_squared_logarithmic_error')","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-22T14:44:32.551877Z","iopub.execute_input":"2024-12-22T14:44:32.552266Z","iopub.status.idle":"2024-12-22T14:44:32.561101Z","shell.execute_reply.started":"2024-12-22T14:44:32.552238Z","shell.execute_reply":"2024-12-22T14:44:32.560191Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(x_train, y_train, epochs=300, batch_size=512, validation_split=0.2)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-22T15:03:04.435679Z","iopub.execute_input":"2024-12-22T15:03:04.436112Z","iopub.status.idle":"2024-12-22T15:30:27.001499Z","shell.execute_reply.started":"2024-12-22T15:03:04.436079Z","shell.execute_reply":"2024-12-22T15:30:27.000597Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Evaluate the model\nloss = model.evaluate(x_train, y_train)\nprint(f\"Test Loss: {loss}\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-22T13:59:13.880005Z","iopub.status.idle":"2024-12-22T13:59:13.880295Z","shell.execute_reply.started":"2024-12-22T13:59:13.880154Z","shell.execute_reply":"2024-12-22T13:59:13.880169Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"s = model.predict(x_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-22T15:32:18.492462Z","iopub.execute_input":"2024-12-22T15:32:18.493479Z","iopub.status.idle":"2024-12-22T15:32:59.724347Z","shell.execute_reply.started":"2024-12-22T15:32:18.493434Z","shell.execute_reply":"2024-12-22T15:32:59.723362Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"s = s.reshape(-1)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-22T15:32:59.726381Z","iopub.execute_input":"2024-12-22T15:32:59.726888Z","iopub.status.idle":"2024-12-22T15:32:59.731194Z","shell.execute_reply.started":"2024-12-22T15:32:59.726842Z","shell.execute_reply":"2024-12-22T15:32:59.730314Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"output = pd.DataFrame(\n    {\n        'id' : test['id'] ,\n        'Premium Amount' : s\n    }\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-22T15:33:07.344574Z","iopub.execute_input":"2024-12-22T15:33:07.344966Z","iopub.status.idle":"2024-12-22T15:33:07.351117Z","shell.execute_reply.started":"2024-12-22T15:33:07.344938Z","shell.execute_reply":"2024-12-22T15:33:07.350169Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"output.to_csv('output.csv',index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-22T15:33:07.682386Z","iopub.execute_input":"2024-12-22T15:33:07.682779Z","iopub.status.idle":"2024-12-22T15:33:08.660307Z","shell.execute_reply.started":"2024-12-22T15:33:07.682745Z","shell.execute_reply":"2024-12-22T15:33:08.65955Z"}},"outputs":[],"execution_count":null}]}