{"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":"none","dataSources":[{"sourceId":82611,"databundleVersionId":9553358,"sourceType":"competition"}],"dockerImageVersionId":30786,"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)\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\npd.set_option('display.max_columns', None)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-10-07T16:24:00.445Z","iopub.execute_input":"2024-10-07T16:24:00.445472Z","iopub.status.idle":"2024-10-07T16:24:00.454404Z","shell.execute_reply.started":"2024-10-07T16:24:00.445431Z","shell.execute_reply":"2024-10-07T16:24:00.453306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = pd.read_csv(\"/kaggle/input/brist1d/train.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:24:01.038487Z","iopub.execute_input":"2024-10-07T16:24:01.039559Z","iopub.status.idle":"2024-10-07T16:24:09.456427Z","shell.execute_reply.started":"2024-10-07T16:24:01.039512Z","shell.execute_reply":"2024-10-07T16:24:09.455239Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head(10)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:24:09.458278Z","iopub.execute_input":"2024-10-07T16:24:09.458662Z","iopub.status.idle":"2024-10-07T16:24:09.807466Z","shell.execute_reply.started":"2024-10-07T16:24:09.458625Z","shell.execute_reply":"2024-10-07T16:24:09.806395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# EDA 🧪","metadata":{}},{"cell_type":"code","source":"\n\n# Sample data\ndata = {'activity': ['Indoor climbing','Run','Strength training','Swim','Bike','Dancing','Stairclimber','Spinning','Walking','HIIT','Outdoor Bike','Walk','Aerobic Workout','Tennis','Workout','Hike','Zumba','Sport','Yoga','Swimming','Weights','Running']}\ndf = pd.DataFrame(data)\n\n# Create a dictionary that maps each unique activity to a number\nunique_activities = {activity: i+1 for i, activity in enumerate(df['activity'].dropna().unique())}\nprint(\"Activity Mapping Dictionary:\", unique_activities)\n\n\n","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:24:09.80903Z","iopub.execute_input":"2024-10-07T16:24:09.8095Z","iopub.status.idle":"2024-10-07T16:24:09.820314Z","shell.execute_reply.started":"2024-10-07T16:24:09.80945Z","shell.execute_reply":"2024-10-07T16:24:09.819217Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in train.columns:\n    if 'activity' in col:\n        # Assign values based on the dictionary and set -1 for empty values\n        train[col] = train[col].apply(lambda x: unique_activities.get(x, -1) if x != '' else -1)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:24:09.823505Z","iopub.execute_input":"2024-10-07T16:24:09.824004Z","iopub.status.idle":"2024-10-07T16:24:15.428428Z","shell.execute_reply.started":"2024-10-07T16:24:09.823965Z","shell.execute_reply":"2024-10-07T16:24:15.427478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train.head(10)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:24:15.42975Z","iopub.execute_input":"2024-10-07T16:24:15.430101Z","iopub.status.idle":"2024-10-07T16:24:15.768806Z","shell.execute_reply.started":"2024-10-07T16:24:15.430065Z","shell.execute_reply":"2024-10-07T16:24:15.767759Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train =train.fillna(-1)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:24:15.770068Z","iopub.execute_input":"2024-10-07T16:24:15.770397Z","iopub.status.idle":"2024-10-07T16:24:16.086076Z","shell.execute_reply.started":"2024-10-07T16:24:15.770363Z","shell.execute_reply":"2024-10-07T16:24:16.085169Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Extract components\ntrain['hour'] = pd.to_datetime(train['time'], format='%H:%M:%S').dt.hour\ntrain['minute'] = pd.to_datetime(train['time'], format='%H:%M:%S').dt.minute\ntrain['second'] = pd.to_datetime(train['time'], format='%H:%M:%S').dt.second\n\n# Display the updated DataFram\n","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:24:16.087657Z","iopub.execute_input":"2024-10-07T16:24:16.088029Z","iopub.status.idle":"2024-10-07T16:24:16.189407Z","shell.execute_reply.started":"2024-10-07T16:24:16.087994Z","shell.execute_reply":"2024-10-07T16:24:16.188312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train['hour_sin'] = np.sin(2 * np.pi * train['hour'] / 24)\ntrain['hour_cos'] = np.cos(2 * np.pi * train['hour'] / 24)\n\n# Similarly, you can create cyclical features for minutes or seconds if needed\ntrain['minute_sin'] = np.sin(2 * np.pi * train['minute'] / 60)\ntrain['minute_cos'] = np.cos(2 * np.pi * train['minute'] / 60)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:24:16.190771Z","iopub.execute_input":"2024-10-07T16:24:16.191153Z","iopub.status.idle":"2024-10-07T16:24:16.214965Z","shell.execute_reply.started":"2024-10-07T16:24:16.191116Z","shell.execute_reply":"2024-10-07T16:24:16.213928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train = train.drop(['hour','minute','second'],axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:24:16.216434Z","iopub.execute_input":"2024-10-07T16:24:16.216776Z","iopub.status.idle":"2024-10-07T16:24:16.456311Z","shell.execute_reply.started":"2024-10-07T16:24:16.21674Z","shell.execute_reply":"2024-10-07T16:24:16.455357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\nX = train.drop(['id','p_num','time','bg+1:00'],axis=1)  # Feature columns\ny = train['bg+1:00']  # Target column\n\n# Split the data (80% training, 20% testing)\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:24:16.459298Z","iopub.execute_input":"2024-10-07T16:24:16.459658Z","iopub.status.idle":"2024-10-07T16:24:17.434787Z","shell.execute_reply.started":"2024-10-07T16:24:16.459624Z","shell.execute_reply":"2024-10-07T16:24:17.433893Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Model🤖","metadata":{}},{"cell_type":"code","source":"from xgboost import XGBRegressor\nfrom sklearn.metrics import mean_squared_error\nmodel = XGBRegressor(n_estimators=100, learning_rate=0.1, random_state=42)\nmodel.fit(X_train, y_train)\n\n# Make predictions on the test set\ny_pred = model.predict(X_test)\n\n# Evaluate the model using Mean Squared Error\nmse = mean_squared_error(y_test, y_pred)\nrmse = mse ** 0.5  # Root Mean Squared Error\n\nprint(f'Root Mean Squared Error (RMSE): {rmse}')","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:24:17.436049Z","iopub.execute_input":"2024-10-07T16:24:17.436389Z","iopub.status.idle":"2024-10-07T16:24:44.335539Z","shell.execute_reply.started":"2024-10-07T16:24:17.436356Z","shell.execute_reply":"2024-10-07T16:24:44.334531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Infrence🔮","metadata":{}},{"cell_type":"code","source":"test = pd.read_csv(\"/kaggle/input/brist1d/test.csv\")","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:27:13.225353Z","iopub.execute_input":"2024-10-07T16:27:13.22577Z","iopub.status.idle":"2024-10-07T16:27:13.414291Z","shell.execute_reply.started":"2024-10-07T16:27:13.225732Z","shell.execute_reply":"2024-10-07T16:27:13.413394Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in train.columns:\n    if 'activity' in col:\n        # Assign values based on the dictionary and set -1 for empty values\n        test[col] = test[col].apply(lambda x: unique_activities.get(x, -1) if x != '' else -1)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:27:13.478066Z","iopub.execute_input":"2024-10-07T16:27:13.478929Z","iopub.status.idle":"2024-10-07T16:27:13.624734Z","shell.execute_reply.started":"2024-10-07T16:27:13.478888Z","shell.execute_reply":"2024-10-07T16:27:13.623576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test =test.fillna(-1)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:27:13.740039Z","iopub.execute_input":"2024-10-07T16:27:13.740962Z","iopub.status.idle":"2024-10-07T16:27:13.75458Z","shell.execute_reply.started":"2024-10-07T16:27:13.740918Z","shell.execute_reply":"2024-10-07T16:27:13.753699Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['hour'] = pd.to_datetime(test['time'], format='%H:%M:%S').dt.hour\ntest['minute'] = pd.to_datetime(test['time'], format='%H:%M:%S').dt.minute\ntest['second'] = pd.to_datetime(test['time'], format='%H:%M:%S').dt.second","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:27:14.032926Z","iopub.execute_input":"2024-10-07T16:27:14.033718Z","iopub.status.idle":"2024-10-07T16:27:14.050182Z","shell.execute_reply.started":"2024-10-07T16:27:14.033678Z","shell.execute_reply":"2024-10-07T16:27:14.048924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test['hour_sin'] = np.sin(2 * np.pi * test['hour'] / 24)\ntest['hour_cos'] = np.cos(2 * np.pi * test['hour'] / 24)\n\n# Similarly, you can create cyclical features for minutes or seconds if needed\ntest['minute_sin'] = np.sin(2 * np.pi * test['minute'] / 60)\ntest['minute_cos'] = np.cos(2 * np.pi * test['minute'] / 60)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:27:14.340947Z","iopub.execute_input":"2024-10-07T16:27:14.341665Z","iopub.status.idle":"2024-10-07T16:27:14.354422Z","shell.execute_reply.started":"2024-10-07T16:27:14.341611Z","shell.execute_reply":"2024-10-07T16:27:14.353285Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.DataFrame()\nsubmission['id'] = test['id']","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:27:14.662771Z","iopub.execute_input":"2024-10-07T16:27:14.663203Z","iopub.status.idle":"2024-10-07T16:27:14.67067Z","shell.execute_reply.started":"2024-10-07T16:27:14.663165Z","shell.execute_reply":"2024-10-07T16:27:14.669544Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test.drop(['hour','minute','second','id','p_num','time'],axis=1)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:27:15.232832Z","iopub.execute_input":"2024-10-07T16:27:15.233791Z","iopub.status.idle":"2024-10-07T16:27:15.245156Z","shell.execute_reply.started":"2024-10-07T16:27:15.233747Z","shell.execute_reply":"2024-10-07T16:27:15.243877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(test)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:27:15.6815Z","iopub.execute_input":"2024-10-07T16:27:15.682299Z","iopub.status.idle":"2024-10-07T16:27:15.757528Z","shell.execute_reply.started":"2024-10-07T16:27:15.682248Z","shell.execute_reply":"2024-10-07T16:27:15.75658Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission['bg+1:00'] = y_pred","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:27:16.244825Z","iopub.execute_input":"2024-10-07T16:27:16.245807Z","iopub.status.idle":"2024-10-07T16:27:16.250926Z","shell.execute_reply.started":"2024-10-07T16:27:16.245761Z","shell.execute_reply":"2024-10-07T16:27:16.249851Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:27:16.767703Z","iopub.execute_input":"2024-10-07T16:27:16.768664Z","iopub.status.idle":"2024-10-07T16:27:16.778392Z","shell.execute_reply.started":"2024-10-07T16:27:16.768622Z","shell.execute_reply":"2024-10-07T16:27:16.777423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2024-10-07T16:27:17.521734Z","iopub.execute_input":"2024-10-07T16:27:17.522173Z","iopub.status.idle":"2024-10-07T16:27:17.537507Z","shell.execute_reply.started":"2024-10-07T16:27:17.522134Z","shell.execute_reply":"2024-10-07T16:27:17.536599Z"},"trusted":true},"execution_count":null,"outputs":[]}]}