{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.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":59156,"databundleVersionId":13874099,"sourceType":"competition"}],"dockerImageVersionId":31192,"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","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:18:52.459494Z","iopub.execute_input":"2025-11-27T13:18:52.459815Z","iopub.status.idle":"2025-11-27T13:18:59.765468Z","shell.execute_reply.started":"2025-11-27T13:18:52.459790Z","shell.execute_reply":"2025-11-27T13:18:59.764586Z"},"_kg_hide-output":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import StandardScaler, LabelEncoder\nfrom sklearn.metrics import accuracy_score, classification_report, confusion_matrix\nfrom sklearn.linear_model import LogisticRegression\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:19:50.335609Z","iopub.execute_input":"2025-11-27T13:19:50.336077Z","iopub.status.idle":"2025-11-27T13:19:51.590610Z","shell.execute_reply.started":"2025-11-27T13:19:50.336050Z","shell.execute_reply":"2025-11-27T13:19:51.589695Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = pd.read_csv(\"/kaggle/input/MABe-mouse-behavior-detection/train.csv\")\ndf.head()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:19:55.311777Z","iopub.execute_input":"2025-11-27T13:19:55.312242Z","iopub.status.idle":"2025-11-27T13:19:55.410168Z","shell.execute_reply.started":"2025-11-27T13:19:55.312216Z","shell.execute_reply":"2025-11-27T13:19:55.409430Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df.shape            # row, column\ndf.info()           # data types\ndf.describe()       # statistics\ndf.isnull().sum()   # missing values\ndf.nunique()        # unique values\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:19:57.872591Z","iopub.execute_input":"2025-11-27T13:19:57.872938Z","iopub.status.idle":"2025-11-27T13:19:57.957396Z","shell.execute_reply.started":"2025-11-27T13:19:57.872911Z","shell.execute_reply":"2025-11-27T13:19:57.956576Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"df = df.fillna(df.mode().iloc[0])\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:20:01.469063Z","iopub.execute_input":"2025-11-27T13:20:01.469382Z","iopub.status.idle":"2025-11-27T13:20:01.552342Z","shell.execute_reply.started":"2025-11-27T13:20:01.469356Z","shell.execute_reply":"2025-11-27T13:20:01.551317Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\n\n# LabelEncoder object\nle = LabelEncoder()\n\n# find all categorical columns\ncat_cols = df.select_dtypes(include=['object']).columns\n\n# apply label encoding to each column\nfor col in cat_cols:\n    df[col] = le.fit_transform(df[col].astype(str))\n\ndf.head()\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:20:04.249973Z","iopub.execute_input":"2025-11-27T13:20:04.250292Z","iopub.status.idle":"2025-11-27T13:20:04.341248Z","shell.execute_reply.started":"2025-11-27T13:20:04.250267Z","shell.execute_reply":"2025-11-27T13:20:04.340385Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = df.drop(\"tracking_method\", axis=1)\ny = df[\"tracking_method\"]\n\nX_train, X_val, y_train, y_val = train_test_split(\n    X, y, test_size=0.2, random_state=42\n)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:20:08.229391Z","iopub.execute_input":"2025-11-27T13:20:08.230062Z","iopub.status.idle":"2025-11-27T13:20:08.243967Z","shell.execute_reply.started":"2025-11-27T13:20:08.230034Z","shell.execute_reply":"2025-11-27T13:20:08.242936Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"scaler = StandardScaler()\nX_train = scaler.fit_transform(X_train)\nX_val = scaler.transform(X_val)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:20:12.551611Z","iopub.execute_input":"2025-11-27T13:20:12.551945Z","iopub.status.idle":"2025-11-27T13:20:12.589226Z","shell.execute_reply.started":"2025-11-27T13:20:12.551919Z","shell.execute_reply":"2025-11-27T13:20:12.588443Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = LogisticRegression(max_iter=200)\nmodel.fit(X_train, y_train)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:20:15.089272Z","iopub.execute_input":"2025-11-27T13:20:15.090174Z","iopub.status.idle":"2025-11-27T13:20:15.934351Z","shell.execute_reply.started":"2025-11-27T13:20:15.090140Z","shell.execute_reply":"2025-11-27T13:20:15.932974Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_pred = model.predict(X_val)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:20:19.188038Z","iopub.execute_input":"2025-11-27T13:20:19.188353Z","iopub.status.idle":"2025-11-27T13:20:19.193459Z","shell.execute_reply.started":"2025-11-27T13:20:19.188329Z","shell.execute_reply":"2025-11-27T13:20:19.192664Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"Accuracy:\", accuracy_score(y_val, y_pred))\nprint(\"\\nClassification Report:\\n\", classification_report(y_val, y_pred))\n\nsns.heatmap(confusion_matrix(y_val, y_pred), annot=True, cmap=\"Blues\")\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:20:21.451222Z","iopub.execute_input":"2025-11-27T13:20:21.451546Z","iopub.status.idle":"2025-11-27T13:20:21.781137Z","shell.execute_reply.started":"2025-11-27T13:20:21.451520Z","shell.execute_reply":"2025-11-27T13:20:21.780044Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\ndf.head()\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:20:25.560221Z","iopub.execute_input":"2025-11-27T13:20:25.560903Z","iopub.status.idle":"2025-11-27T13:20:25.580346Z","shell.execute_reply.started":"2025-11-27T13:20:25.560860Z","shell.execute_reply":"2025-11-27T13:20:25.579388Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import pandas as pd\n\ntest = pd.read_csv(\"/kaggle/input/MABe-mouse-behavior-detection/test.csv\")\ntest.head()\n\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-27T13:22:22.683681Z","iopub.execute_input":"2025-11-27T13:22:22.684052Z","iopub.status.idle":"2025-11-27T13:22:22.710864Z","shell.execute_reply.started":"2025-11-27T13:22:22.684024Z","shell.execute_reply":"2025-11-27T13:22:22.710001Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"\n","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}