{"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":"gpu","dataSources":[{"sourceId":113366,"databundleVersionId":13521426,"sourceType":"competition"}],"dockerImageVersionId":31090,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nfrom sklearn.feature_extraction.text import TfidfVectorizer\nfrom sklearn.naive_bayes import MultinomialNB\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.metrics import classification_report, confusion_matrix,f1_score\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-08-29T00:16:45.701701Z","iopub.execute_input":"2025-08-29T00:16:45.702050Z","iopub.status.idle":"2025-08-29T00:16:45.706496Z","shell.execute_reply.started":"2025-08-29T00:16:45.702028Z","shell.execute_reply":"2025-08-29T00:16:45.705646Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train_path = \"/kaggle/input/comments-classification/Dataset/train.csv\"   \ntest_path = \"/kaggle/input/comments-classification/Dataset/test.csv\"\n\ntrain_df = pd.read_csv(train_path)\ntest_df = pd.read_csv(test_path)\n\nprint(\"Train shape:\", train_df.shape)\nprint(\"Test shape:\", test_df.shape)\nprint(train_df.head())","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-28T23:59:14.601436Z","iopub.execute_input":"2025-08-28T23:59:14.602245Z","iopub.status.idle":"2025-08-28T23:59:17.581961Z","shell.execute_reply.started":"2025-08-28T23:59:14.602212Z","shell.execute_reply":"2025-08-28T23:59:17.581155Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X_train = train_df[\"comment_text\"]\ny_train = train_df[\"psychotic_depression\"]\nX_test = test_df[\"comment_text\"]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-28T23:59:24.596797Z","iopub.execute_input":"2025-08-28T23:59:24.597545Z","iopub.status.idle":"2025-08-28T23:59:24.604375Z","shell.execute_reply.started":"2025-08-28T23:59:24.597516Z","shell.execute_reply":"2025-08-28T23:59:24.603512Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train.value_counts()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-29T00:03:48.745642Z","iopub.execute_input":"2025-08-29T00:03:48.746431Z","iopub.status.idle":"2025-08-29T00:03:48.757598Z","shell.execute_reply.started":"2025-08-29T00:03:48.746408Z","shell.execute_reply":"2025-08-29T00:03:48.756978Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model = make_pipeline(\n    TfidfVectorizer(stop_words=\"english\", max_features=10000),\n    MultinomialNB(class_prior=[0.5, 0.5])\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-29T00:11:44.903445Z","iopub.execute_input":"2025-08-29T00:11:44.904073Z","iopub.status.idle":"2025-08-29T00:11:44.908106Z","shell.execute_reply.started":"2025-08-29T00:11:44.904047Z","shell.execute_reply":"2025-08-29T00:11:44.907429Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"model.fit(X_train, y_train)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-29T00:11:46.435216Z","iopub.execute_input":"2025-08-29T00:11:46.435490Z","iopub.status.idle":"2025-08-29T00:11:53.764551Z","shell.execute_reply.started":"2025-08-29T00:11:46.435468Z","shell.execute_reply":"2025-08-29T00:11:53.763939Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"y_train_pred = model.predict(X_train)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-29T00:17:04.474876Z","iopub.execute_input":"2025-08-29T00:17:04.475421Z","iopub.status.idle":"2025-08-29T00:17:11.056480Z","shell.execute_reply.started":"2025-08-29T00:17:04.475398Z","shell.execute_reply":"2025-08-29T00:17:11.055729Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"print(\"\\nClassification Report (Train):\\n\")\nprint(f1_score(y_train, y_train_pred))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-29T00:17:00.062587Z","iopub.execute_input":"2025-08-29T00:17:00.062965Z","iopub.status.idle":"2025-08-29T00:17:00.132170Z","shell.execute_reply.started":"2025-08-29T00:17:00.062939Z","shell.execute_reply":"2025-08-29T00:17:00.131248Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_preds = model.predict(X_test)\nids = list(range(1, len(test_preds) + 1))\nresults = pd.DataFrame({\n    \"ID\": ids,\n    \"psychotic_depression\": test_preds\n})","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-29T00:38:52.375770Z","iopub.execute_input":"2025-08-29T00:38:52.376497Z","iopub.status.idle":"2025-08-29T00:38:57.776885Z","shell.execute_reply.started":"2025-08-29T00:38:52.376474Z","shell.execute_reply":"2025-08-29T00:38:57.776290Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"results = results.sort_values(by=\"ID\")\n\nresults.to_csv(\"test_predictions.csv\", index=False)\nresults.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-08-29T00:39:01.841312Z","iopub.execute_input":"2025-08-29T00:39:01.841928Z","iopub.status.idle":"2025-08-29T00:39:01.944910Z","shell.execute_reply.started":"2025-08-29T00:39:01.841905Z","shell.execute_reply":"2025-08-29T00:39:01.944348Z"}},"outputs":[],"execution_count":null}]}