{"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":10737,"databundleVersionId":290346,"sourceType":"competition"}],"dockerImageVersionId":30786,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2024-10-11T08:46:34.160181Z","iopub.execute_input":"2024-10-11T08:46:34.162019Z","iopub.status.idle":"2024-10-11T08:46:34.177119Z","shell.execute_reply.started":"2024-10-11T08:46:34.161925Z","shell.execute_reply":"2024-10-11T08:46:34.175223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"raw_df = pd.read_csv('/kaggle/input/quora-insincere-questions-classification/train.csv')","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:46:36.557027Z","iopub.execute_input":"2024-10-11T08:46:36.557566Z","iopub.status.idle":"2024-10-11T08:46:41.332721Z","shell.execute_reply.started":"2024-10-11T08:46:36.557519Z","shell.execute_reply":"2024-10-11T08:46:41.331095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"raw_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:46:50.320102Z","iopub.execute_input":"2024-10-11T08:46:50.320582Z","iopub.status.idle":"2024-10-11T08:46:50.347300Z","shell.execute_reply.started":"2024-10-11T08:46:50.320538Z","shell.execute_reply":"2024-10-11T08:46:50.345753Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sincere_df = raw_df[raw_df.target == 0] \nsincere_df.question_text[:10]","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:46:52.714860Z","iopub.execute_input":"2024-10-11T08:46:52.715316Z","iopub.status.idle":"2024-10-11T08:46:52.847344Z","shell.execute_reply.started":"2024-10-11T08:46:52.715274Z","shell.execute_reply":"2024-10-11T08:46:52.846073Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"insincere_df = raw_df[raw_df.target == 1] \ninsincere_df.question_text[:10]","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:46:55.183718Z","iopub.execute_input":"2024-10-11T08:46:55.184214Z","iopub.status.idle":"2024-10-11T08:46:55.213081Z","shell.execute_reply.started":"2024-10-11T08:46:55.184170Z","shell.execute_reply":"2024-10-11T08:46:55.211835Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"raw_df.target.value_counts(normalize = True)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:46:58.091861Z","iopub.execute_input":"2024-10-11T08:46:58.092354Z","iopub.status.idle":"2024-10-11T08:46:58.120645Z","shell.execute_reply.started":"2024-10-11T08:46:58.092308Z","shell.execute_reply":"2024-10-11T08:46:58.118934Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"raw_df.target.value_counts(normalize = True).plot(kind = 'bar');","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:00.130466Z","iopub.execute_input":"2024-10-11T08:47:00.130962Z","iopub.status.idle":"2024-10-11T08:47:00.417491Z","shell.execute_reply.started":"2024-10-11T08:47:00.130918Z","shell.execute_reply":"2024-10-11T08:47:00.416274Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df = pd.read_csv('/kaggle/input/quora-insincere-questions-classification/test.csv')\ntest_df.head(5)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:03.115771Z","iopub.execute_input":"2024-10-11T08:47:03.116305Z","iopub.status.idle":"2024-10-11T08:47:04.438818Z","shell.execute_reply.started":"2024-10-11T08:47:03.116261Z","shell.execute_reply":"2024-10-11T08:47:04.437650Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df = pd.read_csv('/kaggle/input/quora-insincere-questions-classification/sample_submission.csv')\nsub_df.head(3)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:06.119885Z","iopub.execute_input":"2024-10-11T08:47:06.120323Z","iopub.status.idle":"2024-10-11T08:47:06.486324Z","shell.execute_reply.started":"2024-10-11T08:47:06.120281Z","shell.execute_reply":"2024-10-11T08:47:06.485205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Tokenization\n\nsplitting a document into words and separators","metadata":{}},{"cell_type":"code","source":"import nltk\nfrom nltk.tokenize import word_tokenize","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:09.435231Z","iopub.execute_input":"2024-10-11T08:47:09.436215Z","iopub.status.idle":"2024-10-11T08:47:09.441240Z","shell.execute_reply.started":"2024-10-11T08:47:09.436171Z","shell.execute_reply":"2024-10-11T08:47:09.439796Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q0 = sincere_df.question_text[1]\nq0","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:11.525427Z","iopub.execute_input":"2024-10-11T08:47:11.525975Z","iopub.status.idle":"2024-10-11T08:47:11.537551Z","shell.execute_reply.started":"2024-10-11T08:47:11.525924Z","shell.execute_reply":"2024-10-11T08:47:11.536265Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q0_tok  = word_tokenize(q0)\nq0_tok","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:13.475620Z","iopub.execute_input":"2024-10-11T08:47:13.476089Z","iopub.status.idle":"2024-10-11T08:47:13.485698Z","shell.execute_reply.started":"2024-10-11T08:47:13.476047Z","shell.execute_reply":"2024-10-11T08:47:13.484530Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Stop Word Removal\n\nRemoving commonly occuring words","metadata":{}},{"cell_type":"code","source":"from nltk.corpus import stopwords","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:17.115555Z","iopub.execute_input":"2024-10-11T08:47:17.115986Z","iopub.status.idle":"2024-10-11T08:47:17.121720Z","shell.execute_reply.started":"2024-10-11T08:47:17.115947Z","shell.execute_reply":"2024-10-11T08:47:17.120337Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"english_stopwords = stopwords.words('english')","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:18.770674Z","iopub.execute_input":"2024-10-11T08:47:18.771623Z","iopub.status.idle":"2024-10-11T08:47:18.778636Z","shell.execute_reply.started":"2024-10-11T08:47:18.771575Z","shell.execute_reply":"2024-10-11T08:47:18.777411Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def remove_stopwords(tokens):\n    return[word for word in tokens if word.lower() not in english_stopwords]\n","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:21.107494Z","iopub.execute_input":"2024-10-11T08:47:21.107951Z","iopub.status.idle":"2024-10-11T08:47:21.114139Z","shell.execute_reply.started":"2024-10-11T08:47:21.107907Z","shell.execute_reply":"2024-10-11T08:47:21.112946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q0_norm = remove_stopwords(q0_tok)\nq0_norm","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:23.799617Z","iopub.execute_input":"2024-10-11T08:47:23.800057Z","iopub.status.idle":"2024-10-11T08:47:23.808394Z","shell.execute_reply.started":"2024-10-11T08:47:23.800014Z","shell.execute_reply":"2024-10-11T08:47:23.807034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Stemming\n\n\"go\", \"gone\", \"going\" -> \"go\"\n\"birds\", \"bird\" -> \"bird\"","metadata":{}},{"cell_type":"code","source":"from nltk.stem.snowball import SnowballStemmer\nstemmer = SnowballStemmer(language = 'english')","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:26.076892Z","iopub.execute_input":"2024-10-11T08:47:26.077302Z","iopub.status.idle":"2024-10-11T08:47:26.084084Z","shell.execute_reply.started":"2024-10-11T08:47:26.077265Z","shell.execute_reply":"2024-10-11T08:47:26.082700Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"q0_stem = [stemmer.stem(word) for word in q0_norm]\nq0_stem","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:28.378514Z","iopub.execute_input":"2024-10-11T08:47:28.378948Z","iopub.status.idle":"2024-10-11T08:47:28.387584Z","shell.execute_reply.started":"2024-10-11T08:47:28.378909Z","shell.execute_reply":"2024-10-11T08:47:28.386203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Implement Bag of Words \n\n\nOutline:\n\n1. Create a vocabulary using Count Vectorizer\n2. Transform text to vectors using Count Vectorizer\n3. Configure text preprocessing in Count Vectorizer","metadata":{}},{"cell_type":"code","source":"small_df = raw_df[:5]\nsmall_df","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:30.554499Z","iopub.execute_input":"2024-10-11T08:47:30.554918Z","iopub.status.idle":"2024-10-11T08:47:30.567742Z","shell.execute_reply.started":"2024-10-11T08:47:30.554880Z","shell.execute_reply":"2024-10-11T08:47:30.566498Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.feature_extraction.text import CountVectorizer","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:33.236150Z","iopub.execute_input":"2024-10-11T08:47:33.236646Z","iopub.status.idle":"2024-10-11T08:47:33.242282Z","shell.execute_reply.started":"2024-10-11T08:47:33.236602Z","shell.execute_reply":"2024-10-11T08:47:33.241084Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"small_vect = CountVectorizer()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:35.678921Z","iopub.execute_input":"2024-10-11T08:47:35.679380Z","iopub.status.idle":"2024-10-11T08:47:35.684970Z","shell.execute_reply.started":"2024-10-11T08:47:35.679337Z","shell.execute_reply":"2024-10-11T08:47:35.683769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"small_vect.fit(small_df.question_text)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:37.754175Z","iopub.execute_input":"2024-10-11T08:47:37.755264Z","iopub.status.idle":"2024-10-11T08:47:37.769638Z","shell.execute_reply.started":"2024-10-11T08:47:37.755219Z","shell.execute_reply":"2024-10-11T08:47:37.768392Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"small_vect.get_feature_names_out()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:39.578032Z","iopub.execute_input":"2024-10-11T08:47:39.578522Z","iopub.status.idle":"2024-10-11T08:47:39.586996Z","shell.execute_reply.started":"2024-10-11T08:47:39.578478Z","shell.execute_reply":"2024-10-11T08:47:39.585792Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Transforming documents into Vectors","metadata":{}},{"cell_type":"code","source":"small_vectors = small_vect.transform(small_df.question_text)\nsmall_vectors","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:44.796382Z","iopub.execute_input":"2024-10-11T08:47:44.796830Z","iopub.status.idle":"2024-10-11T08:47:44.805583Z","shell.execute_reply.started":"2024-10-11T08:47:44.796791Z","shell.execute_reply":"2024-10-11T08:47:44.804605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"small_vectors.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:48.092829Z","iopub.execute_input":"2024-10-11T08:47:48.093276Z","iopub.status.idle":"2024-10-11T08:47:48.101294Z","shell.execute_reply.started":"2024-10-11T08:47:48.093234Z","shell.execute_reply":"2024-10-11T08:47:48.099987Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"small_vectors[0].toarray()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:50.559622Z","iopub.execute_input":"2024-10-11T08:47:50.560057Z","iopub.status.idle":"2024-10-11T08:47:50.569184Z","shell.execute_reply.started":"2024-10-11T08:47:50.560018Z","shell.execute_reply":"2024-10-11T08:47:50.567845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"small_vectors.toarray()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:55.085460Z","iopub.execute_input":"2024-10-11T08:47:55.085913Z","iopub.status.idle":"2024-10-11T08:47:55.094726Z","shell.execute_reply.started":"2024-10-11T08:47:55.085872Z","shell.execute_reply":"2024-10-11T08:47:55.093651Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Configuring Count Vectorizer Parameters","metadata":{}},{"cell_type":"code","source":"stemmer = SnowballStemmer(language='english')","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:47:59.005979Z","iopub.execute_input":"2024-10-11T08:47:59.006409Z","iopub.status.idle":"2024-10-11T08:47:59.011842Z","shell.execute_reply.started":"2024-10-11T08:47:59.006370Z","shell.execute_reply":"2024-10-11T08:47:59.010518Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def tokenize(text):\n    return[stemmer.stem(word) for word in word_tokenize(text)]","metadata":{"execution":{"iopub.status.busy":"2024-10-11T05:17:43.396699Z","iopub.execute_input":"2024-10-11T05:17:43.397102Z","iopub.status.idle":"2024-10-11T05:17:43.402451Z","shell.execute_reply.started":"2024-10-11T05:17:43.397058Z","shell.execute_reply":"2024-10-11T05:17:43.401409Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"## example \ntokenize('What is the really (dealing) here?')","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:48:02.155236Z","iopub.execute_input":"2024-10-11T08:48:02.156234Z","iopub.status.idle":"2024-10-11T08:48:02.163995Z","shell.execute_reply.started":"2024-10-11T08:48:02.156188Z","shell.execute_reply":"2024-10-11T08:48:02.162779Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"vectorizer = CountVectorizer(lowercase=True, \n                             tokenizer=tokenize, ## our own tokenizer\n                             stop_words=english_stopwords,\n                             max_features=1000)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:48:03.998355Z","iopub.execute_input":"2024-10-11T08:48:03.998824Z","iopub.status.idle":"2024-10-11T08:48:04.005387Z","shell.execute_reply.started":"2024-10-11T08:48:03.998777Z","shell.execute_reply":"2024-10-11T08:48:04.003839Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nvectorizer.fit(raw_df.question_text)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:48:07.318264Z","iopub.execute_input":"2024-10-11T08:48:07.319502Z","iopub.status.idle":"2024-10-11T08:58:54.110524Z","shell.execute_reply.started":"2024-10-11T08:48:07.319415Z","shell.execute_reply":"2024-10-11T08:58:54.109247Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ninputs = vectorizer.transform(raw_df.question_text)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T08:59:01.280115Z","iopub.execute_input":"2024-10-11T08:59:01.280599Z","iopub.status.idle":"2024-10-11T09:09:48.986064Z","shell.execute_reply.started":"2024-10-11T08:59:01.280557Z","shell.execute_reply":"2024-10-11T09:09:48.984733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"inputs.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:09:57.934152Z","iopub.execute_input":"2024-10-11T09:09:57.934609Z","iopub.status.idle":"2024-10-11T09:09:57.942174Z","shell.execute_reply.started":"2024-10-11T09:09:57.934570Z","shell.execute_reply":"2024-10-11T09:09:57.940979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_df.head()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:10:00.361492Z","iopub.execute_input":"2024-10-11T09:10:00.362420Z","iopub.status.idle":"2024-10-11T09:10:00.375655Z","shell.execute_reply.started":"2024-10-11T09:10:00.362373Z","shell.execute_reply":"2024-10-11T09:10:00.374312Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\ntest_inputs = vectorizer.transform(test_df.question_text)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:10:10.878567Z","iopub.execute_input":"2024-10-11T09:10:10.879023Z","iopub.status.idle":"2024-10-11T09:13:13.518243Z","shell.execute_reply.started":"2024-10-11T09:10:10.878980Z","shell.execute_reply":"2024-10-11T09:13:13.516926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:13:17.719905Z","iopub.execute_input":"2024-10-11T09:13:17.720352Z","iopub.status.idle":"2024-10-11T09:13:17.726882Z","shell.execute_reply.started":"2024-10-11T09:13:17.720310Z","shell.execute_reply":"2024-10-11T09:13:17.725710Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_val, y_train, y_val= train_test_split(inputs,\n                                                 raw_df.target, \n                                                 test_size=0.3,\n                                                 random_state=42)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:13:20.180472Z","iopub.execute_input":"2024-10-11T09:13:20.180924Z","iopub.status.idle":"2024-10-11T09:13:20.625920Z","shell.execute_reply.started":"2024-10-11T09:13:20.180883Z","shell.execute_reply":"2024-10-11T09:13:20.624672Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:13:22.394322Z","iopub.execute_input":"2024-10-11T09:13:22.394775Z","iopub.status.idle":"2024-10-11T09:13:22.402428Z","shell.execute_reply.started":"2024-10-11T09:13:22.394734Z","shell.execute_reply":"2024-10-11T09:13:22.401221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_val.shape","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:13:24.357277Z","iopub.execute_input":"2024-10-11T09:13:24.358255Z","iopub.status.idle":"2024-10-11T09:13:24.365810Z","shell.execute_reply.started":"2024-10-11T09:13:24.358208Z","shell.execute_reply":"2024-10-11T09:13:24.364587Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Training the model","metadata":{}},{"cell_type":"code","source":"from xgboost import XGBClassifier","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:13:26.866787Z","iopub.execute_input":"2024-10-11T09:13:26.867228Z","iopub.status.idle":"2024-10-11T09:13:26.873197Z","shell.execute_reply.started":"2024-10-11T09:13:26.867189Z","shell.execute_reply":"2024-10-11T09:13:26.871829Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%time\nxgb_clf = XGBClassifier(\n    n_estimators=1000,      # Increase the number of trees\n    learning_rate=0.05,    # Shrinkage to help avoid overfitting\n    max_depth=6,           # Tree depth\n    subsample=0.8,         # Use 80% of the data for each tree\n    colsample_bytree=0.8,  # Use 80% of the features for each tree\n    gamma=1,               # Regularization to avoid overfitting\n    objective='binary:logistic',  # Binary classification\n    eval_metric='auc',     # AUC as evaluation metric\n    use_label_encoder=False\n)\n\nxgb_clf_model =  xgb_clf.fit(X_train , y_train)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:13:33.437640Z","iopub.execute_input":"2024-10-11T09:13:33.438116Z","iopub.status.idle":"2024-10-11T09:14:20.683550Z","shell.execute_reply.started":"2024-10-11T09:13:33.438072Z","shell.execute_reply":"2024-10-11T09:14:20.682366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgb_clf_model.score(X_train , y_train)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:14:25.282970Z","iopub.execute_input":"2024-10-11T09:14:25.283426Z","iopub.status.idle":"2024-10-11T09:14:52.997093Z","shell.execute_reply.started":"2024-10-11T09:14:25.283383Z","shell.execute_reply":"2024-10-11T09:14:52.995741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import accuracy_score\nval_preds = xgb_clf_model.predict(X_val)\naccuracy = accuracy_score(y_val , val_preds)\naccuracy","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:15:25.320829Z","iopub.execute_input":"2024-10-11T09:15:25.321746Z","iopub.status.idle":"2024-10-11T09:15:36.969785Z","shell.execute_reply.started":"2024-10-11T09:15:25.321700Z","shell.execute_reply":"2024-10-11T09:15:36.968634Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import f1_score\nf1_score(y_val, val_preds)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:16:10.488051Z","iopub.execute_input":"2024-10-11T09:16:10.488519Z","iopub.status.idle":"2024-10-11T09:16:10.645771Z","shell.execute_reply.started":"2024-10-11T09:16:10.488479Z","shell.execute_reply":"2024-10-11T09:16:10.644408Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.metrics import confusion_matrix\nimport seaborn as sns\nimport matplotlib.pyplot as plt\n\ncm = confusion_matrix(y_val, val_preds)\nsns.heatmap(cm, annot=True, fmt='d', cmap='Blues')\nplt.xlabel('Predicted')\nplt.ylabel('True')\nplt.title('Confusion Matrix')\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:16:13.725758Z","iopub.execute_input":"2024-10-11T09:16:13.726210Z","iopub.status.idle":"2024-10-11T09:16:14.059287Z","shell.execute_reply.started":"2024-10-11T09:16:13.726169Z","shell.execute_reply":"2024-10-11T09:16:14.057846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_preds = xgb_clf_model.predict(test_inputs)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:16:17.226368Z","iopub.execute_input":"2024-10-11T09:16:17.227289Z","iopub.status.idle":"2024-10-11T09:16:28.380361Z","shell.execute_reply.started":"2024-10-11T09:16:17.227227Z","shell.execute_reply":"2024-10-11T09:16:28.379396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df.prediction = test_preds","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:16:49.587713Z","iopub.execute_input":"2024-10-11T09:16:49.588142Z","iopub.status.idle":"2024-10-11T09:16:49.594692Z","shell.execute_reply.started":"2024-10-11T09:16:49.588104Z","shell.execute_reply":"2024-10-11T09:16:49.593537Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df.prediction.value_counts()","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:16:51.680645Z","iopub.execute_input":"2024-10-11T09:16:51.681278Z","iopub.status.idle":"2024-10-11T09:16:51.694753Z","shell.execute_reply.started":"2024-10-11T09:16:51.681223Z","shell.execute_reply":"2024-10-11T09:16:51.693605Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sub_df.to_csv('submission.csv', index=None)","metadata":{"execution":{"iopub.status.busy":"2024-10-11T09:16:53.994364Z","iopub.execute_input":"2024-10-11T09:16:53.994818Z","iopub.status.idle":"2024-10-11T09:16:54.759957Z","shell.execute_reply.started":"2024-10-11T09:16:53.994778Z","shell.execute_reply":"2024-10-11T09:16:54.758993Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}