{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":83916,"databundleVersionId":9356278,"sourceType":"competition"}],"dockerImageVersionId":30746,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"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)\nfrom sklearn import preprocessing\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LinearRegression\nfrom tqdm.auto import tqdm\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.metrics import mean_squared_error\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":"2024-08-14T19:04:18.219893Z","iopub.execute_input":"2024-08-14T19:04:18.220303Z","iopub.status.idle":"2024-08-14T19:04:18.230372Z","shell.execute_reply.started":"2024-08-14T19:04:18.220272Z","shell.execute_reply":"2024-08-14T19:04:18.229243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv(\"/kaggle/input/final-hackathon/Train.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:02:09.656322Z","iopub.execute_input":"2024-08-14T19:02:09.656782Z","iopub.status.idle":"2024-08-14T19:02:12.135890Z","shell.execute_reply.started":"2024-08-14T19:02:09.656716Z","shell.execute_reply":"2024-08-14T19:02:12.134855Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(train_df.shape)","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:02:12.137811Z","iopub.execute_input":"2024-08-14T19:02:12.138180Z","iopub.status.idle":"2024-08-14T19:02:12.143652Z","shell.execute_reply.started":"2024-08-14T19:02:12.138150Z","shell.execute_reply":"2024-08-14T19:02:12.142527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:02:12.145472Z","iopub.execute_input":"2024-08-14T19:02:12.145958Z","iopub.status.idle":"2024-08-14T19:02:12.177940Z","shell.execute_reply.started":"2024-08-14T19:02:12.145915Z","shell.execute_reply":"2024-08-14T19:02:12.176815Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.columns","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:02:12.180779Z","iopub.execute_input":"2024-08-14T19:02:12.181569Z","iopub.status.idle":"2024-08-14T19:02:12.188778Z","shell.execute_reply.started":"2024-08-14T19:02:12.181532Z","shell.execute_reply":"2024-08-14T19:02:12.187653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Discarding all columns that are non numeric\ntrain_df = train_df.select_dtypes(include=[np.number])","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:02:12.190243Z","iopub.execute_input":"2024-08-14T19:02:12.190587Z","iopub.status.idle":"2024-08-14T19:02:12.237100Z","shell.execute_reply.started":"2024-08-14T19:02:12.190545Z","shell.execute_reply":"2024-08-14T19:02:12.236013Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df.columns","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:02:12.238351Z","iopub.execute_input":"2024-08-14T19:02:12.238661Z","iopub.status.idle":"2024-08-14T19:02:12.245531Z","shell.execute_reply.started":"2024-08-14T19:02:12.238636Z","shell.execute_reply":"2024-08-14T19:02:12.244439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# handling missing values\ntrain_df.fillna(train_df.mean(), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:02:22.780569Z","iopub.execute_input":"2024-08-14T19:02:22.781513Z","iopub.status.idle":"2024-08-14T19:02:22.946773Z","shell.execute_reply.started":"2024-08-14T19:02:22.781475Z","shell.execute_reply":"2024-08-14T19:02:22.945766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:02:26.236138Z","iopub.execute_input":"2024-08-14T19:02:26.236522Z","iopub.status.idle":"2024-08-14T19:02:26.299450Z","shell.execute_reply.started":"2024-08-14T19:02:26.236491Z","shell.execute_reply":"2024-08-14T19:02:26.298392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = train_df.drop(['FPS'], axis=1)\ny = train_df['FPS']","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:02:35.379703Z","iopub.execute_input":"2024-08-14T19:02:35.380789Z","iopub.status.idle":"2024-08-14T19:02:35.418883Z","shell.execute_reply.started":"2024-08-14T19:02:35.380740Z","shell.execute_reply":"2024-08-14T19:02:35.417949Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_val, y_train, y_val = train_test_split(X, y, test_size = 0.2)","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:02:41.742992Z","iopub.execute_input":"2024-08-14T19:02:41.743358Z","iopub.status.idle":"2024-08-14T19:02:41.866354Z","shell.execute_reply.started":"2024-08-14T19:02:41.743331Z","shell.execute_reply":"2024-08-14T19:02:41.865294Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(X_train.shape, X_val.shape)","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:02:42.805743Z","iopub.execute_input":"2024-08-14T19:02:42.806696Z","iopub.status.idle":"2024-08-14T19:02:42.811900Z","shell.execute_reply.started":"2024-08-14T19:02:42.806656Z","shell.execute_reply":"2024-08-14T19:02:42.810689Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"lr=LinearRegression()\nlr.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:02:44.486905Z","iopub.execute_input":"2024-08-14T19:02:44.487319Z","iopub.status.idle":"2024-08-14T19:02:45.094216Z","shell.execute_reply.started":"2024-08-14T19:02:44.487287Z","shell.execute_reply":"2024-08-14T19:02:45.093055Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = lr.predict(X_val)","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:03:34.225836Z","iopub.execute_input":"2024-08-14T19:03:34.226280Z","iopub.status.idle":"2024-08-14T19:03:34.243969Z","shell.execute_reply.started":"2024-08-14T19:03:34.226246Z","shell.execute_reply":"2024-08-14T19:03:34.242533Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"val_mse = mean_squared_error(y_val, y_pred)\nprint(f'Validation MSE: {val_mse}')","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:04:22.066821Z","iopub.execute_input":"2024-08-14T19:04:22.067769Z","iopub.status.idle":"2024-08-14T19:04:22.074944Z","shell.execute_reply.started":"2024-08-14T19:04:22.067696Z","shell.execute_reply":"2024-08-14T19:04:22.073811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data = pd.read_csv(\"/kaggle/input/final-hackathon/Test.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:04:50.922073Z","iopub.execute_input":"2024-08-14T19:04:50.923313Z","iopub.status.idle":"2024-08-14T19:04:51.355205Z","shell.execute_reply.started":"2024-08-14T19:04:50.923267Z","shell.execute_reply":"2024-08-14T19:04:51.353781Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data.shape","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:04:55.030109Z","iopub.execute_input":"2024-08-14T19:04:55.030567Z","iopub.status.idle":"2024-08-14T19:04:55.037993Z","shell.execute_reply.started":"2024-08-14T19:04:55.030516Z","shell.execute_reply":"2024-08-14T19:04:55.036910Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Index=test_data['Index']\ntest_data.drop(['Index'],axis=1,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:05:01.614692Z","iopub.execute_input":"2024-08-14T19:05:01.615790Z","iopub.status.idle":"2024-08-14T19:05:01.631514Z","shell.execute_reply.started":"2024-08-14T19:05:01.615721Z","shell.execute_reply":"2024-08-14T19:05:01.630190Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Apply any preprocessing done to Train data on test data as well\ntest_data = test_data.select_dtypes(include=[np.number])\ntest_data.fillna(test_data.mean(), inplace=True)","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:07:06.951010Z","iopub.execute_input":"2024-08-14T19:07:06.951854Z","iopub.status.idle":"2024-08-14T19:07:06.991686Z","shell.execute_reply.started":"2024-08-14T19:07:06.951813Z","shell.execute_reply":"2024-08-14T19:07:06.990637Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test = lr.predict(test_data)","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:07:13.974885Z","iopub.execute_input":"2024-08-14T19:07:13.975920Z","iopub.status.idle":"2024-08-14T19:07:13.990311Z","shell.execute_reply.started":"2024-08-14T19:07:13.975881Z","shell.execute_reply":"2024-08-14T19:07:13.989060Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_test","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:07:18.257935Z","iopub.execute_input":"2024-08-14T19:07:18.258645Z","iopub.status.idle":"2024-08-14T19:07:18.265245Z","shell.execute_reply.started":"2024-08-14T19:07:18.258610Z","shell.execute_reply":"2024-08-14T19:07:18.264206Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result = pd.DataFrame({\n    'Index': Index,\n    'FPS': y_test\n})","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:07:27.739083Z","iopub.execute_input":"2024-08-14T19:07:27.739883Z","iopub.status.idle":"2024-08-14T19:07:27.745499Z","shell.execute_reply.started":"2024-08-14T19:07:27.739842Z","shell.execute_reply":"2024-08-14T19:07:27.744224Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:07:32.021144Z","iopub.execute_input":"2024-08-14T19:07:32.021894Z","iopub.status.idle":"2024-08-14T19:07:32.034062Z","shell.execute_reply.started":"2024-08-14T19:07:32.021859Z","shell.execute_reply":"2024-08-14T19:07:32.032814Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"result.to_csv(\"submission.csv\", index=False) #(for making submission file)","metadata":{"execution":{"iopub.status.busy":"2024-08-14T19:07:39.386570Z","iopub.execute_input":"2024-08-14T19:07:39.387241Z","iopub.status.idle":"2024-08-14T19:07:39.488604Z","shell.execute_reply.started":"2024-08-14T19:07:39.387203Z","shell.execute_reply":"2024-08-14T19:07:39.487700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}