{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":3004,"databundleVersionId":861823,"sourceType":"competition"}],"dockerImageVersionId":30918,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.metrics import classification_report, confusion_matrix, ConfusionMatrixDisplay, accuracy_score\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-02T10:29:36.453948Z","iopub.execute_input":"2025-03-02T10:29:36.454256Z","iopub.status.idle":"2025-03-02T10:29:39.302880Z","shell.execute_reply.started":"2025-03-02T10:29:36.454215Z","shell.execute_reply":"2025-03-02T10:29:39.301658Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ntest = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')\nsam = pd.read_csv('/kaggle/input/digit-recognizer/sample_submission.csv')\ntrain.head(3)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-02T10:29:45.643036Z","iopub.execute_input":"2025-03-02T10:29:45.643420Z","iopub.status.idle":"2025-03-02T10:29:51.244656Z","shell.execute_reply.started":"2025-03-02T10:29:45.643392Z","shell.execute_reply":"2025-03-02T10:29:51.243440Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"X = train.drop(columns=['label'])\ny = train['label']\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)\nrf_model = RandomForestClassifier(n_estimators=1000, random_state=42)\nrf_model.fit(X_train, y_train)\ny_pred = rf_model.predict(X_test)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-02T10:30:44.323021Z","iopub.execute_input":"2025-03-02T10:30:44.323429Z","iopub.status.idle":"2025-03-02T10:34:14.682017Z","shell.execute_reply.started":"2025-03-02T10:30:44.323400Z","shell.execute_reply":"2025-03-02T10:34:14.680965Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"accuracy = accuracy_score(y_test,y_pred)\nprint(f'Accuracy: {accuracy: .2f} %')\nprint(classification_report(y_test, y_pred))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-02T10:34:14.683317Z","iopub.execute_input":"2025-03-02T10:34:14.683835Z","iopub.status.idle":"2025-03-02T10:34:14.732515Z","shell.execute_reply.started":"2025-03-02T10:34:14.683799Z","shell.execute_reply":"2025-03-02T10:34:14.731272Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"cm = confusion_matrix(y_test, y_pred)\ndisp = ConfusionMatrixDisplay(confusion_matrix=cm)\ndisp.plot(cmap=plt.cm.Blues)\nplt.title('Confusion Matrix for Divorce Status Classification')\nplt.ylabel('True label')\nplt.xlabel('Predicted label')\nplt.grid(False)\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-02T10:34:14.734345Z","iopub.execute_input":"2025-03-02T10:34:14.734666Z","iopub.status.idle":"2025-03-02T10:34:15.397844Z","shell.execute_reply.started":"2025-03-02T10:34:14.734638Z","shell.execute_reply":"2025-03-02T10:34:15.396805Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"Predictions = rf_model.predict(test)\nsam['Label']= Predictions\nsam.to_csv('submission.csv',index=False)\nsam.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-03-02T10:34:15.398798Z","iopub.execute_input":"2025-03-02T10:34:15.399101Z","iopub.status.idle":"2025-03-02T10:34:26.207727Z","shell.execute_reply.started":"2025-03-02T10:34:15.399073Z","shell.execute_reply":"2025-03-02T10:34:26.206326Z"}},"outputs":[],"execution_count":null}]}