{"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# 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":"2022-04-06T19:47:07.822084Z","iopub.execute_input":"2022-04-06T19:47:07.822349Z","iopub.status.idle":"2022-04-06T19:47:07.831522Z","shell.execute_reply.started":"2022-04-06T19:47:07.822319Z","shell.execute_reply":"2022-04-06T19:47:07.830733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train=pd.read_csv('../input/Kannada-MNIST/train.csv')\ntest=pd.read_csv('../input/Kannada-MNIST/test.csv')\nsubmission = pd.read_csv('../input/Kannada-MNIST/sample_submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:47:07.862025Z","iopub.execute_input":"2022-04-06T19:47:07.862316Z","iopub.status.idle":"2022-04-06T19:47:10.919178Z","shell.execute_reply.started":"2022-04-06T19:47:07.862288Z","shell.execute_reply":"2022-04-06T19:47:10.918317Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X, y = (train.drop(['label'], axis=1), train.label)","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:47:10.922880Z","iopub.execute_input":"2022-04-06T19:47:10.923098Z","iopub.status.idle":"2022-04-06T19:47:11.039793Z","shell.execute_reply.started":"2022-04-06T19:47:10.923073Z","shell.execute_reply":"2022-04-06T19:47:11.038859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X = X / 255\nX.max().max()","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:47:11.041238Z","iopub.execute_input":"2022-04-06T19:47:11.041603Z","iopub.status.idle":"2022-04-06T19:47:11.277683Z","shell.execute_reply.started":"2022-04-06T19:47:11.041561Z","shell.execute_reply":"2022-04-06T19:47:11.276889Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test = test / 255","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:47:11.279977Z","iopub.execute_input":"2022-04-06T19:47:11.280220Z","iopub.status.idle":"2022-04-06T19:47:11.297495Z","shell.execute_reply.started":"2022-04-06T19:47:11.280183Z","shell.execute_reply":"2022-04-06T19:47:11.296882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from xgboost import XGBClassifier\nfrom sklearn.metrics import accuracy_score","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:47:11.298579Z","iopub.execute_input":"2022-04-06T19:47:11.298833Z","iopub.status.idle":"2022-04-06T19:47:11.304444Z","shell.execute_reply.started":"2022-04-06T19:47:11.298796Z","shell.execute_reply":"2022-04-06T19:47:11.303611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"xgb = XGBClassifier(tree_method='gpu_hist', objective = \"multi:softmax\", num_class = 10, eval_metric=\"mlogloss\", max_depth = 5, n_estimators = 333, subsample = 0.89, colsample_bytree = 0.45, reg_alpha = 0, reg_lambda =1, learning_rate = 0.16)\nfitted = xgb.fit(X, y)","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:47:11.305783Z","iopub.execute_input":"2022-04-06T19:47:11.306340Z","iopub.status.idle":"2022-04-06T19:47:46.342351Z","shell.execute_reply.started":"2022-04-06T19:47:11.306266Z","shell.execute_reply":"2022-04-06T19:47:46.341481Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trainPred = fitted.predict(X)\n\nprint(\"Final training score for XGB: \", accuracy_score(y, trainPred))\n\ntest_x = test.values[:,1:]\nxgbTestPred = fitted.predict(test_x)","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:47:46.344111Z","iopub.execute_input":"2022-04-06T19:47:46.344352Z","iopub.status.idle":"2022-04-06T19:47:51.103676Z","shell.execute_reply.started":"2022-04-06T19:47:46.344317Z","shell.execute_reply":"2022-04-06T19:47:51.103053Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission['label'] = xgbTestPred\nsubmission.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:47:51.107111Z","iopub.execute_input":"2022-04-06T19:47:51.108803Z","iopub.status.idle":"2022-04-06T19:47:51.123609Z","shell.execute_reply.started":"2022-04-06T19:47:51.108771Z","shell.execute_reply":"2022-04-06T19:47:51.122945Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"submission.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-06T19:47:51.124546Z","iopub.execute_input":"2022-04-06T19:47:51.124776Z","iopub.status.idle":"2022-04-06T19:47:51.135017Z","shell.execute_reply.started":"2022-04-06T19:47:51.124742Z","shell.execute_reply":"2022-04-06T19:47:51.134130Z"},"trusted":true},"execution_count":null,"outputs":[]}]}