{"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","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport os\nimport warnings\nimport optuna\nfrom joblib import load\nimport joblib\n\nfrom sklearn.pipeline import Pipeline\nfrom sklearn.compose import ColumnTransformer\nfrom sklearn.impute import SimpleImputer\nfrom sklearn.preprocessing import StandardScaler, OneHotEncoder\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.metrics import accuracy_score, confusion_matrix, classification_report\nfrom sklearn.model_selection import train_test_split, cross_val_score\n\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as mpatches","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:10:47.661947Z","iopub.execute_input":"2023-08-17T10:10:47.662338Z","iopub.status.idle":"2023-08-17T10:10:49.434751Z","shell.execute_reply.started":"2023-08-17T10:10:47.662308Z","shell.execute_reply":"2023-08-17T10:10:49.433596Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"warnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:10:53.383842Z","iopub.execute_input":"2023-08-17T10:10:53.384411Z","iopub.status.idle":"2023-08-17T10:10:53.392921Z","shell.execute_reply.started":"2023-08-17T10:10:53.384358Z","shell.execute_reply":"2023-08-17T10:10:53.389882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"daily_df = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/daily_metadata.csv')\ndefog_df = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/defog_metadata.csv')\ntdcsfog_df = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/tdcsfog_metadata.csv')\nevents_df = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/events.csv')\nsubjects_df = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/subjects.csv')\ntasks_df = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/tasks.csv')","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:10:58.27391Z","iopub.execute_input":"2023-08-17T10:10:58.274616Z","iopub.status.idle":"2023-08-17T10:10:58.349932Z","shell.execute_reply.started":"2023-08-17T10:10:58.274582Z","shell.execute_reply":"2023-08-17T10:10:58.348859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"daily_df.head()\n# The Daily Living (daily) dataset, comprising one week of continuous 24/7 recordings from sixty-five subjects. \n# Forty-five subjects exhibit FOG symptoms and also have series in the defog dataset, \n# while the other twenty subjects do not exhibit FOG symptoms and do not have series elsewhere in the data.\n# Id The data series the event occured in.\n# subjects.csv Metadata for each Subject in the study, including their Age and Sex.\n# Visit Lab visits consist of a baseline assessment, \n# two post-treatment assessments for different treatment stages, and one follow-up assessment.","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:11:01.754602Z","iopub.execute_input":"2023-08-17T10:11:01.75499Z","iopub.status.idle":"2023-08-17T10:11:01.779041Z","shell.execute_reply.started":"2023-08-17T10:11:01.75496Z","shell.execute_reply":"2023-08-17T10:11:01.777761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"daily_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:11:08.667133Z","iopub.execute_input":"2023-08-17T10:11:08.667601Z","iopub.status.idle":"2023-08-17T10:11:08.676044Z","shell.execute_reply.started":"2023-08-17T10:11:08.667567Z","shell.execute_reply":"2023-08-17T10:11:08.674775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"daily_df[daily_df['Visit']==1]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"daily_df[daily_df['Visit']==2]","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"daily_df[daily_df['Visit']==1].shape","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"daily_df[daily_df['Visit']==2].shape","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:11:25.991861Z","iopub.execute_input":"2023-08-17T10:11:25.992241Z","iopub.status.idle":"2023-08-17T10:11:26.002719Z","shell.execute_reply.started":"2023-08-17T10:11:25.992212Z","shell.execute_reply":"2023-08-17T10:11:26.001715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog_df.head()\n\n# The DeFOG (defog) dataset, \n# comprising data series collected in the subject's home, \n# as subjects completed a FOG-provoking protocol\n\n# Medication Subjects may have been either off or on anti-parkinsonian medication during the recording.","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:11:29.110466Z","iopub.execute_input":"2023-08-17T10:11:29.110871Z","iopub.status.idle":"2023-08-17T10:11:29.124104Z","shell.execute_reply.started":"2023-08-17T10:11:29.110841Z","shell.execute_reply":"2023-08-17T10:11:29.122882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"defog_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:11:32.90715Z","iopub.execute_input":"2023-08-17T10:11:32.907891Z","iopub.status.idle":"2023-08-17T10:11:32.915042Z","shell.execute_reply.started":"2023-08-17T10:11:32.907847Z","shell.execute_reply":"2023-08-17T10:11:32.913834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog_df.head()\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog_df.shape","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:11:38.874752Z","iopub.execute_input":"2023-08-17T10:11:38.87513Z","iopub.status.idle":"2023-08-17T10:11:38.881536Z","shell.execute_reply.started":"2023-08-17T10:11:38.875103Z","shell.execute_reply":"2023-08-17T10:11:38.880576Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog_df['Visit'].value_counts()\n# 2 kere ziyarete gelme sayisi 245.","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:11:41.749904Z","iopub.execute_input":"2023-08-17T10:11:41.750775Z","iopub.status.idle":"2023-08-17T10:11:41.761897Z","shell.execute_reply.started":"2023-08-17T10:11:41.750729Z","shell.execute_reply":"2023-08-17T10:11:41.760904Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tdcsfog_df['Visit'].value_counts().plot(kind='barh')\n\n# number of visits garphic\n# most visit number is \"2\"","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:11:45.602813Z","iopub.execute_input":"2023-08-17T10:11:45.603246Z","iopub.status.idle":"2023-08-17T10:11:45.892242Z","shell.execute_reply.started":"2023-08-17T10:11:45.603215Z","shell.execute_reply":"2023-08-17T10:11:45.89129Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"events.csv Metadata for each FoG event in all data series. The event times agree with the labels in the data series.\n\nId The data series the event occured in.\nInit Time (s) the event began.\nCompletion Time (s) the event ended.\nType Whether StartHesitation, Turn, or Walking.\nKinetic Whether the event was kinetic (1) and involved movement, or akinetic (0) and static.","metadata":{}},{"cell_type":"code","source":"events_df.tail()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"events_df['Type'].value_counts().to_frame().style.background_gradient()","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:11:55.193742Z","iopub.execute_input":"2023-08-17T10:11:55.194405Z","iopub.status.idle":"2023-08-17T10:11:55.261537Z","shell.execute_reply.started":"2023-08-17T10:11:55.194365Z","shell.execute_reply":"2023-08-17T10:11:55.260409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize=(15,7))\nax =sns.countplot(x='Type',data=events_df, palette=\"rocket\")\nax.set_title('Distribution of Type', fontsize=16, color='grey')\nfor container in ax.containers:\n    ax.bar_label(container)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:26:05.8872Z","iopub.execute_input":"2023-08-17T10:26:05.887603Z","iopub.status.idle":"2023-08-17T10:26:06.19737Z","shell.execute_reply.started":"2023-08-17T10:26:05.887571Z","shell.execute_reply":"2023-08-17T10:26:06.196362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize=(15,7))\nax =sns.countplot(x='Type',data=events_df, hue='Kinetic', palette=\"rocket\")\nax.set_title('Distribution of Type by Kinetic', fontsize=16, color='grey')\nfor container in ax.containers:\n    ax.bar_label(container)\nplt.show()\n\n","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:26:15.085061Z","iopub.execute_input":"2023-08-17T10:26:15.085672Z","iopub.status.idle":"2023-08-17T10:26:15.490147Z","shell.execute_reply.started":"2023-08-17T10:26:15.085633Z","shell.execute_reply":"2023-08-17T10:26:15.489Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#events_df['Type'].value_counts().plot(kind='bar', color='pink')","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:13:18.534777Z","iopub.execute_input":"2023-08-17T10:13:18.535183Z","iopub.status.idle":"2023-08-17T10:13:18.789358Z","shell.execute_reply.started":"2023-08-17T10:13:18.535144Z","shell.execute_reply":"2023-08-17T10:13:18.788352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"subjects_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:26:50.846228Z","iopub.execute_input":"2023-08-17T10:26:50.846666Z","iopub.status.idle":"2023-08-17T10:26:50.865748Z","shell.execute_reply.started":"2023-08-17T10:26:50.846633Z","shell.execute_reply":"2023-08-17T10:26:50.864497Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tasks_df.head()","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:27:02.6913Z","iopub.execute_input":"2023-08-17T10:27:02.691688Z","iopub.status.idle":"2023-08-17T10:27:02.709026Z","shell.execute_reply.started":"2023-08-17T10:27:02.691657Z","shell.execute_reply":"2023-08-17T10:27:02.707869Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset = events_df\ndataset.info()","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:27:11.935473Z","iopub.execute_input":"2023-08-17T10:27:11.936115Z","iopub.status.idle":"2023-08-17T10:27:11.955794Z","shell.execute_reply.started":"2023-08-17T10:27:11.936078Z","shell.execute_reply":"2023-08-17T10:27:11.954734Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset.isnull().sum()\n\n# Type and Kinetic columns have missing values.","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:28:09.232777Z","iopub.execute_input":"2023-08-17T10:28:09.233182Z","iopub.status.idle":"2023-08-17T10:28:09.24893Z","shell.execute_reply.started":"2023-08-17T10:28:09.233152Z","shell.execute_reply":"2023-08-17T10:28:09.247622Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"***FEATURE ENGINEERING:***\n\n**ADDING 'StartHesitation', 'Turn', 'Walking' COLUMNS**\n\n**ADDING 'DURATION' COLUMN**\n\n**ADDING 'TARGET' COLUMN**","metadata":{}},{"cell_type":"code","source":"def preprocessing_data(dataset):\n    dataset.drop_duplicates(inplace=True)\n    # Converting categorical features\n    dataset['Type'] = dataset['Type'].astype('category')\n    dataset['StartHesitation'] = np.where(dataset['Type'] == 'StartHesitation', 1, 0) # Where True, yield x=1, otherwise yield y=0.\n    dataset['Turn'] = np.where(dataset['Type'] == 'Turn', 1, 0)\n    dataset['Walking'] = np.where(dataset['Type'] == 'Walking', 1, 0)\n    # Creating a feature called Duration\n    dataset['Duration'] = dataset['Completion'] - dataset['Init']\n    # Defining the value of the target feature\n    dataset['Target'] = np.where(dataset['Type'] == 'StartHesitation', dataset['StartHesitation'], \n                                 np.where(dataset['Type'] == 'Turn', dataset['Turn'], dataset['Walking']))\n    return dataset","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:31:45.165721Z","iopub.execute_input":"2023-08-17T10:31:45.166091Z","iopub.status.idle":"2023-08-17T10:31:45.173637Z","shell.execute_reply.started":"2023-08-17T10:31:45.166062Z","shell.execute_reply":"2023-08-17T10:31:45.172597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dataset.head()","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:49:31.629748Z","iopub.execute_input":"2023-08-17T10:49:31.630168Z","iopub.status.idle":"2023-08-17T10:49:31.648369Z","shell.execute_reply.started":"2023-08-17T10:49:31.630136Z","shell.execute_reply":"2023-08-17T10:49:31.647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_X_Y(dataset):\n    X = dataset.drop(['StartHesitation', 'Turn', 'Walking', 'Target'], axis=1)\n    Y = dataset['Target']\n    return X, Y","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:49:25.614128Z","iopub.execute_input":"2023-08-17T10:49:25.614576Z","iopub.status.idle":"2023-08-17T10:49:25.620578Z","shell.execute_reply.started":"2023-08-17T10:49:25.614541Z","shell.execute_reply":"2023-08-17T10:49:25.61946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def model_evaluation(X, Y, model):\n    score = cross_val_score(model, X, Y, cv=5, scoring='accuracy')\n    return np.mean(score), np.std(score)","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:49:38.933813Z","iopub.execute_input":"2023-08-17T10:49:38.934671Z","iopub.status.idle":"2023-08-17T10:49:38.94089Z","shell.execute_reply.started":"2023-08-17T10:49:38.934636Z","shell.execute_reply":"2023-08-17T10:49:38.939235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def submission_evaluation(y_true, y_pred):\n    acc_score= accuracy_score(y_true, y_pred)\n    con_mat = confusion_matrix(y_true, y_pred)\n    return acc_score, con_mat\ndf = preprocessing_data(dataset)\ndf","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:49:41.855855Z","iopub.execute_input":"2023-08-17T10:49:41.856291Z","iopub.status.idle":"2023-08-17T10:49:41.894606Z","shell.execute_reply.started":"2023-08-17T10:49:41.856263Z","shell.execute_reply":"2023-08-17T10:49:41.893456Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.groupby(['Id','Type'])['Duration'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-08-17T11:07:22.329414Z","iopub.execute_input":"2023-08-17T11:07:22.330158Z","iopub.status.idle":"2023-08-17T11:07:22.349844Z","shell.execute_reply.started":"2023-08-17T11:07:22.330124Z","shell.execute_reply":"2023-08-17T11:07:22.348761Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"execution":{"iopub.status.busy":"2023-08-17T11:12:23.680294Z","iopub.execute_input":"2023-08-17T11:12:23.681348Z","iopub.status.idle":"2023-08-17T11:12:24.824103Z","shell.execute_reply.started":"2023-08-17T11:12:23.681307Z","shell.execute_reply":"2023-08-17T11:12:24.822773Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(15,8))\norder_per_month = df.groupby('Month', as_index=False).TotalPrice.sum()\nax = sns.lineplot(x=\"Month\", y=\"TotalPrice\", data=order_per_month)\nax.set_title('Orders per Month');","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import plotly.express as px\nimport cufflinks as cf\nimport plotly.offline","metadata":{"execution":{"iopub.status.busy":"2023-08-17T10:55:37.289656Z","iopub.execute_input":"2023-08-17T10:55:37.290086Z","iopub.status.idle":"2023-08-17T10:55:39.122834Z","shell.execute_reply.started":"2023-08-17T10:55:37.290055Z","shell.execute_reply":"2023-08-17T10:55:39.121473Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['Target'].value_counts()","metadata":{"execution":{"iopub.status.busy":"2023-08-16T19:39:00.586105Z","iopub.execute_input":"2023-08-16T19:39:00.586473Z","iopub.status.idle":"2023-08-16T19:39:00.595803Z","shell.execute_reply.started":"2023-08-16T19:39:00.586444Z","shell.execute_reply":"2023-08-16T19:39:00.594928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.heatmap(df.corr(),annot=True)","metadata":{"execution":{"iopub.status.busy":"2023-08-16T19:40:57.375857Z","iopub.execute_input":"2023-08-16T19:40:57.376237Z","iopub.status.idle":"2023-08-16T19:40:57.890504Z","shell.execute_reply.started":"2023-08-16T19:40:57.376201Z","shell.execute_reply":"2023-08-16T19:40:57.889604Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_test, Y_train, Y_test = train_test_split(df.drop('Target', axis=1), df['Target'], test_size=0.3, random_state=40)","metadata":{"execution":{"iopub.status.busy":"2023-08-16T19:35:00.050772Z","iopub.execute_input":"2023-08-16T19:35:00.051137Z","iopub.status.idle":"2023-08-16T19:35:00.064561Z","shell.execute_reply.started":"2023-08-16T19:35:00.051109Z","shell.execute_reply":"2023-08-16T19:35:00.063353Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating a list of numerical and categorical features\nnumeric_features = ['Init', 'Completion', 'Duration', 'StartHesitation','Turn', 'Walking', 'Kinetic']\ncategorical_features = ['Id', 'Type']","metadata":{"execution":{"iopub.status.busy":"2023-07-08T08:23:03.345305Z","iopub.execute_input":"2023-07-08T08:23:03.345675Z","iopub.status.idle":"2023-07-08T08:23:03.353405Z","shell.execute_reply.started":"2023-07-08T08:23:03.345646Z","shell.execute_reply":"2023-07-08T08:23:03.352149Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Creating transformers for numerical and categorical features\n\nnumeric_transformer = Pipeline(steps=[\n('imputer', SimpleImputer(strategy='median')),\n('scaler', StandardScaler())\n])\n\ncategorical_transformer = Pipeline(steps=[\n('imputer', SimpleImputer\n(strategy='most_frequent')),\n('onehot', OneHotEncoder(handle_unknown='ignore'))\n])","metadata":{"execution":{"iopub.status.busy":"2023-07-08T08:23:12.39092Z","iopub.execute_input":"2023-07-08T08:23:12.391312Z","iopub.status.idle":"2023-07-08T08:23:12.398819Z","shell.execute_reply.started":"2023-07-08T08:23:12.391282Z","shell.execute_reply":"2023-07-08T08:23:12.396213Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"processor = ColumnTransformer(\ntransformers=[\n('numeric', numeric_transformer, numeric_features),\n('categorical', categorical_transformer, categorical_features)\n])","metadata":{"execution":{"iopub.status.busy":"2023-07-08T08:23:19.231998Z","iopub.execute_input":"2023-07-08T08:23:19.232965Z","iopub.status.idle":"2023-07-08T08:23:19.237792Z","shell.execute_reply.started":"2023-07-08T08:23:19.232927Z","shell.execute_reply":"2023-07-08T08:23:19.236766Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sin_pipeline = Pipeline(steps=[('Processor', processor),\n('classifier', RandomForestClassifier())])","metadata":{"execution":{"iopub.status.busy":"2023-07-08T08:23:22.141588Z","iopub.execute_input":"2023-07-08T08:23:22.141996Z","iopub.status.idle":"2023-07-08T08:23:22.146641Z","shell.execute_reply.started":"2023-07-08T08:23:22.141966Z","shell.execute_reply":"2023-07-08T08:23:22.14548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Training the model\nsin_pipeline.fit(X_train, Y_train)","metadata":{"execution":{"iopub.status.busy":"2023-07-08T08:23:27.150383Z","iopub.execute_input":"2023-07-08T08:23:27.150761Z","iopub.status.idle":"2023-07-08T08:23:27.637006Z","shell.execute_reply.started":"2023-07-08T08:23:27.150734Z","shell.execute_reply":"2023-07-08T08:23:27.636093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pred = sin_pipeline.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2023-07-08T08:23:31.437443Z","iopub.execute_input":"2023-07-08T08:23:31.437816Z","iopub.status.idle":"2023-07-08T08:23:31.487053Z","shell.execute_reply.started":"2023-07-08T08:23:31.437787Z","shell.execute_reply":"2023-07-08T08:23:31.486137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predictions = pd.DataFrame({'Id': X_test['Id'], 'Predictions': pred})","metadata":{"execution":{"iopub.status.busy":"2023-07-08T08:23:35.96238Z","iopub.execute_input":"2023-07-08T08:23:35.963069Z","iopub.status.idle":"2023-07-08T08:23:35.967937Z","shell.execute_reply.started":"2023-07-08T08:23:35.963038Z","shell.execute_reply":"2023-07-08T08:23:35.967067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(f\"Accuracy score on test data: {accuracy_score(Y_test, pred)}\")","metadata":{"execution":{"iopub.status.busy":"2023-07-08T08:23:39.446263Z","iopub.execute_input":"2023-07-08T08:23:39.446678Z","iopub.status.idle":"2023-07-08T08:23:39.456298Z","shell.execute_reply.started":"2023-07-08T08:23:39.44663Z","shell.execute_reply":"2023-07-08T08:23:39.455187Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_one = pd.read_csv('/kaggle/input/tlvmc-parkinsons-freezing-gait-prediction/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:31:45.023085Z","iopub.execute_input":"2023-05-23T09:31:45.024123Z","iopub.status.idle":"2023-05-23T09:31:45.271609Z","shell.execute_reply.started":"2023-05-23T09:31:45.024055Z","shell.execute_reply":"2023-05-23T09:31:45.270517Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_two = pd.DataFrame({'Id': ['003f117e14_' + str(i) for i in range(286370)],\n                               'StartHesitation': 0,\n                               'Turn': 0,\n                               'Walking': 0})\n\nfor i in range(len(pred)):\n    id_str = sub_one['Id'][i]\n    sub_two.loc[sub_two['Id'] == id_str, ['StartHesitation', 'Turn', 'Walking']] = pred[i]","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:31:45.27361Z","iopub.execute_input":"2023-05-23T09:31:45.274359Z","iopub.status.idle":"2023-05-23T09:32:25.328513Z","shell.execute_reply.started":"2023-05-23T09:31:45.274324Z","shell.execute_reply":"2023-05-23T09:32:25.327586Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_two.info()","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:32:25.330041Z","iopub.execute_input":"2023-05-23T09:32:25.330434Z","iopub.status.idle":"2023-05-23T09:32:25.419172Z","shell.execute_reply.started":"2023-05-23T09:32:25.330398Z","shell.execute_reply":"2023-05-23T09:32:25.418208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_one.info()","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:32:25.420624Z","iopub.execute_input":"2023-05-23T09:32:25.421224Z","iopub.status.idle":"2023-05-23T09:32:25.514869Z","shell.execute_reply.started":"2023-05-23T09:32:25.421187Z","shell.execute_reply":"2023-05-23T09:32:25.512812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.merge(sub_one[['Id']], sub_two, on='Id', how='left')\nsubmission.fillna(0, inplace=True)\nsubmission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:32:25.516419Z","iopub.execute_input":"2023-05-23T09:32:25.516739Z","iopub.status.idle":"2023-05-23T09:32:27.028113Z","shell.execute_reply.started":"2023-05-23T09:32:25.516707Z","shell.execute_reply":"2023-05-23T09:32:27.027159Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission = pd.read_csv('submission.csv')\nprint(submission)","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:33:19.037319Z","iopub.execute_input":"2023-05-23T09:33:19.03821Z","iopub.status.idle":"2023-05-23T09:33:19.247848Z","shell.execute_reply.started":"2023-05-23T09:33:19.038162Z","shell.execute_reply":"2023-05-23T09:33:19.246685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Save the merged dataset to a CSV file\nsubmission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:33:23.255591Z","iopub.execute_input":"2023-05-23T09:33:23.255949Z","iopub.status.idle":"2023-05-23T09:33:24.303332Z","shell.execute_reply.started":"2023-05-23T09:33:23.255919Z","shell.execute_reply":"2023-05-23T09:33:24.302137Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Saving the model\njoblib.dump(sin_pipeline, 'models.joblib')\n#Loading the model\nload_pipeline = joblib.load('models.joblib')","metadata":{"execution":{"iopub.status.busy":"2023-05-23T09:33:27.485798Z","iopub.execute_input":"2023-05-23T09:33:27.486765Z","iopub.status.idle":"2023-05-23T09:33:27.604293Z","shell.execute_reply.started":"2023-05-23T09:33:27.486719Z","shell.execute_reply":"2023-05-23T09:33:27.603412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}