{"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-06T21:47:22.157881Z","iopub.execute_input":"2022-04-06T21:47:22.158388Z","iopub.status.idle":"2022-04-06T21:47:22.194740Z","shell.execute_reply.started":"2022-04-06T21:47:22.158274Z","shell.execute_reply":"2022-04-06T21:47:22.193553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from xgboost import XGBClassifier\nfrom sklearn.model_selection import train_test_split, RandomizedSearchCV\nfrom sklearn.metrics import accuracy_score\n","metadata":{"execution":{"iopub.status.busy":"2022-04-06T21:47:22.198823Z","iopub.execute_input":"2022-04-06T21:47:22.199078Z","iopub.status.idle":"2022-04-06T21:47:23.431475Z","shell.execute_reply.started":"2022-04-06T21:47:22.199055Z","shell.execute_reply":"2022-04-06T21:47:23.430282Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv('/kaggle/input/Kannada-MNIST/train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-04-06T21:50:41.845443Z","iopub.execute_input":"2022-04-06T21:50:41.845715Z","iopub.status.idle":"2022-04-06T21:50:46.787968Z","shell.execute_reply.started":"2022-04-06T21:50:41.845664Z","shell.execute_reply":"2022-04-06T21:50:46.787308Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X, y = train_data.drop(['label'],axis=1), train_data.label","metadata":{"execution":{"iopub.status.busy":"2022-04-06T21:50:55.229821Z","iopub.execute_input":"2022-04-06T21:50:55.230439Z","iopub.status.idle":"2022-04-06T21:50:55.310877Z","shell.execute_reply.started":"2022-04-06T21:50:55.230413Z","shell.execute_reply":"2022-04-06T21:50:55.310117Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_train, X_val, y_train, y_val = train_test_split(X, y, test_size=0.2)","metadata":{"execution":{"iopub.status.busy":"2022-04-06T21:50:56.254860Z","iopub.execute_input":"2022-04-06T21:50:56.255116Z","iopub.status.idle":"2022-04-06T21:50:56.601222Z","shell.execute_reply.started":"2022-04-06T21:50:56.255092Z","shell.execute_reply":"2022-04-06T21:50:56.600390Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = XGBClassifier()\nmodel.max_depth=8\nmodel.n_estimators=1000\nmodel.learning_rate=0.25\nmodel.subsample = 0.9\neval_set = [(X_val,y_val)]\nmodel.fit(X_train, y_train, early_stopping_rounds=9, eval_set=eval_set, verbose=True)","metadata":{"execution":{"iopub.status.busy":"2022-04-06T21:51:43.399510Z","iopub.execute_input":"2022-04-06T21:51:43.399765Z","iopub.status.idle":"2022-04-06T22:08:24.970783Z","shell.execute_reply.started":"2022-04-06T21:51:43.399743Z","shell.execute_reply":"2022-04-06T22:08:24.969750Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y_pred = model.predict(X_val)\nprint(accuracy_score(y_val,y_pred))","metadata":{"execution":{"iopub.status.busy":"2022-04-06T22:09:20.691641Z","iopub.execute_input":"2022-04-06T22:09:20.691930Z","iopub.status.idle":"2022-04-06T22:09:21.137617Z","shell.execute_reply.started":"2022-04-06T22:09:20.691901Z","shell.execute_reply":"2022-04-06T22:09:21.137127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"test_data = pd.read_csv('/kaggle/input/Kannada-MNIST/test.csv')","metadata":{"execution":{"iopub.status.busy":"2022-04-06T22:09:22.313745Z","iopub.execute_input":"2022-04-06T22:09:22.314218Z","iopub.status.idle":"2022-04-06T22:09:22.733445Z","shell.execute_reply.started":"2022-04-06T22:09:22.314194Z","shell.execute_reply":"2022-04-06T22:09:22.732362Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ids, test_set = test_data.id, test_data.drop(['id'], axis=1) ","metadata":{"execution":{"iopub.status.busy":"2022-04-06T22:09:25.938527Z","iopub.execute_input":"2022-04-06T22:09:25.939454Z","iopub.status.idle":"2022-04-06T22:09:25.949797Z","shell.execute_reply.started":"2022-04-06T22:09:25.939405Z","shell.execute_reply":"2022-04-06T22:09:25.948872Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"final_preds = model.predict(test_set)","metadata":{"execution":{"iopub.status.busy":"2022-04-06T22:09:27.501721Z","iopub.execute_input":"2022-04-06T22:09:27.502355Z","iopub.status.idle":"2022-04-06T22:09:27.726904Z","shell.execute_reply.started":"2022-04-06T22:09:27.502322Z","shell.execute_reply":"2022-04-06T22:09:27.724175Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.Series(final_preds, index=ids, name='label').to_csv('/kaggle/working/submission.csv')","metadata":{"execution":{"iopub.status.busy":"2022-04-06T22:09:28.625902Z","iopub.execute_input":"2022-04-06T22:09:28.627788Z","iopub.status.idle":"2022-04-06T22:09:28.644916Z","shell.execute_reply.started":"2022-04-06T22:09:28.627758Z","shell.execute_reply":"2022-04-06T22:09:28.643505Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}