{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Import Required Libraries"},{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom xgboost import XGBClassifier","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Importing Data\nWe will start project by first importing our data. We have a total of 03 files in our project. \n1. *train.csv* -- This file contains data we have to use for training of the model. \n2. *test.csv* --  This file contains test data that we have to use tomake predictions for test data using our model\n3. submission_sample.csv -- After we have predicted labels (0,1,2,3 etc) for test data using our model, we need to submit our results on Kaggle. This file provides format according to which, the submission has to be done\n4. The only difference between *train.csv* and *test.csv* files is that training data contains one extra column *'Label'* for labels as is a supervised learning problem and we need to provide labeled data at our model"},{"metadata":{"trusted":true},"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/digit-recognizer/train.csv')\ntest = pd.read_csv('/kaggle/input/digit-recognizer/test.csv')\nsubmit_sample = pd.read_csv('/kaggle/input/digit-recognizer/sample_submission.csv')\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Number of Rows and Columns in our Data (Train and Test)"},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Shape of Training Data: ', train.shape)\nprint('Shape of Testing Data: ', test.shape)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"#### As explained earlier, training data contains 785 columns, one more than test data "},{"metadata":{},"cell_type":"markdown","source":"### We wouldn't do any analysis on data rather, we would go for modeling directly \n"},{"metadata":{},"cell_type":"markdown","source":"## Separate labels from training data to feed in to the model\nTo train our model, we need to separate labels (Label column) from our training data and then train our model. \n"},{"metadata":{"trusted":true},"cell_type":"code","source":"X = train.drop(columns=['label'])\nY = train['label']","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Let's import XGBoost Classifier"},{"metadata":{"trusted":true},"cell_type":"code","source":"from xgboost import XGBClassifier","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"xgb = XGBClassifier(n_jobs=5).fit(X,Y)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"#### Note that training may take some time depending upon the system your are running this notebook/code on"},{"metadata":{"trusted":true},"cell_type":"code","source":"y_pred = xgb.predict(test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"result = pd.DataFrame()\nresult['Label'] = y_pred\nresult['ImageId'] = submit_sample.ImageId\nresult.set_index('ImageId')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Finally let's save our result in to a csv file to make it ready for submission. \n"},{"metadata":{"trusted":true},"cell_type":"code","source":"result.to_csv('digit_recognizer_result.csv')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# BOOM! You have completed a kaggle project with remarkable accuracy. Great Job! Happy Coding, Happy Kaggling !!!"}],"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":4,"nbformat_minor":1}