{"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\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":"2023-10-28T12:10:48.063699Z","iopub.execute_input":"2023-10-28T12:10:48.064216Z","iopub.status.idle":"2023-10-28T12:10:48.072582Z","shell.execute_reply.started":"2023-10-28T12:10:48.064193Z","shell.execute_reply":"2023-10-28T12:10:48.07183Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.metrics import accuracy_score\nimport matplotlib.pyplot as plt\ntrain_data= pd.read_csv('/kaggle/input/child-mind-institute-detect-sleep-states/train_events.csv')\ntrain_data.head()\ntrain_data.info()\ntrain_data.describe()\ntrain_data.shape\ntest_data = pd.read_parquet('/kaggle/input/child-mind-institute-detect-sleep-states/test_series.parquet')\ntest_data.head()\ntest_data.info()\ntest_data.describe()\ntest_data.shape\nfrom sklearn.model_selection import train_test_split\n\nX = train_data.drop('event', axis=1)\ny = train_data['event']\n\nX_train, X_valid, y_train, y_valid = train_test_split(X, y, test_size=0.2, random_state=42)\ntrain_data.dtypes\ntest_data.dtypes\ntrain_data.describe()\ntest_data.describe()\ntrain_data.hist(bins=50,figsize=(20,15))\nplt.show()\ntest_data.hist(bins=50,figsize=(20,15))\nplt.show()\nfrom numpy.random import RandomState\nrng = RandomState()\n\ntrain = train_data.sample(frac=0.7, random_state=rng)\ntest = test_data.loc[~test_data.index.isin(train.index)]\ntrain.head()\ntest.head()","metadata":{"execution":{"iopub.status.busy":"2023-10-31T06:51:52.606058Z","iopub.execute_input":"2023-10-31T06:51:52.606398Z","iopub.status.idle":"2023-10-31T06:51:53.861989Z","shell.execute_reply.started":"2023-10-31T06:51:52.606375Z","shell.execute_reply":"2023-10-31T06:51:53.860978Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\n\n# Model training\nmodel = RandomForestClassifier(n_estimators=100, random_state=42)\nmodel.fit(X_train, y_train)\n\n# Make predictions on the validation set\nvalid_preds = model.predict(X_valid)\n\n# Calculate accuracy on the validation set\naccuracy = accuracy_score(y_valid, valid_preds)\nprint(f'Validation Accuracy: {accuracy}')\n\n# Make predictions on the test set\ntest_preds = model.predict(test)\n\n# Create a submission file\nsubmission = pd.DataFrame({'id': test['id'], 'target': test_preds})\nsubmission.to_csv('submission.csv', index=False)\n\n# Optional: Data visualization\nplt.figure(figsize=(8, 6))\nplt.hist(valid_preds, bins=10, alpha=0.5, label='Validation Predictions')\nplt.legend()\nplt.xlabel('Predicted Values')\nplt.ylabel('Frequency')\nplt.show()","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}