{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":16017,"databundleVersionId":708189,"sourceType":"competition"},{"sourceId":8203185,"sourceType":"datasetVersion","datasetId":4859970}],"dockerImageVersionId":30698,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"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)\nfrom sklearn.datasets import fetch_openml\nfrom sklearn import metrics\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom catboost import CatBoostClassifier\nfrom sklearn.metrics import accuracy_score\nfrom sklearn.preprocessing import MinMaxScaler\nfrom joblib import load\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","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_data = pd.read_csv(\"/kaggle/input/Kannada-MNIST/train.csv\")\ntest_data = pd.read_csv(\"/kaggle/input/Kannada-MNIST/test.csv\")\n\nsample_sub = pd.read_csv(\"/kaggle/input/Kannada-MNIST/sample_submission.csv\")","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"scaler = MinMaxScaler()\ncols = train_data.columns[train_data.columns != 'label']\ntrain_data[cols] = scaler.fit_transform(train_data[cols])","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"my_random_state = 32\nhardware_gpu = 'GPU'\nhardware_cpu = 'CPU'\n\nmodel = CatBoostClassifier(\n    thread_count=-1,\n    task_type=hardware_gpu,\n    verbose=False\n)\nX, y = (train_data.drop(['label'], axis=1), train_data.label)\n\nprint(X.shape)\nprint(y.shape)\ntrain_data.shape","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"best_params = {\n    'random_strength': 0.9, 'od_type': 'IncToDec', 'max_leaves': 52, 'learning_rate': 0.0144,\n    'leaf_estimation_method': 'Newton', 'leaf_estimation_iterations': 7, 'l2_leaf_reg': 6.2, 'iterations': 1200,\n    'grow_policy': 'Lossguide', 'depth': 16, 'border_count': 200, 'bagging_temperature': 14.5,\n    'od_type': 'IncToDec',\n    'leaf_estimation_method': 'Newton',\n    'grow_policy': 'Lossguide'\n}","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model_path = '/kaggle/input/cat-boost/cat_boost.txt'\n\nmodel = CatBoostClassifier()\nmodel.load_model(model_path, format='catboost')","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model.set_params(**best_params)\n# model.fit(X, y)","metadata":{"execution":{"iopub.status.busy":"2024-04-20T16:13:31.447489Z","iopub.execute_input":"2024-04-20T16:13:31.448464Z","iopub.status.idle":"2024-04-20T16:14:53.206925Z","shell.execute_reply.started":"2024-04-20T16:13:31.448431Z","shell.execute_reply":"2024-04-20T16:14:53.206058Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = test_data.columns[test_data.columns != 'label']\ntest_data[cols] = scaler.fit_transform(test_data[cols])","metadata":{"execution":{"iopub.status.busy":"2024-04-20T16:20:16.514224Z","iopub.execute_input":"2024-04-20T16:20:16.514974Z","iopub.status.idle":"2024-04-20T16:20:16.694365Z","shell.execute_reply.started":"2024-04-20T16:20:16.514942Z","shell.execute_reply":"2024-04-20T16:20:16.693590Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"X_test = test_data\n\npredictions = model.predict(X_test)","metadata":{"execution":{"iopub.status.busy":"2024-04-20T16:20:19.122506Z","iopub.execute_input":"2024-04-20T16:20:19.123119Z","iopub.status.idle":"2024-04-20T16:20:19.288377Z","shell.execute_reply.started":"2024-04-20T16:20:19.123089Z","shell.execute_reply":"2024-04-20T16:20:19.287549Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sample_sub['label'] = predictions\nsample_sub.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2024-04-20T16:20:21.212490Z","iopub.execute_input":"2024-04-20T16:20:21.212812Z","iopub.status.idle":"2024-04-20T16:20:21.227949Z","shell.execute_reply.started":"2024-04-20T16:20:21.212787Z","shell.execute_reply":"2024-04-20T16:20:21.226903Z"},"trusted":true},"execution_count":null,"outputs":[]}]}