{"cells":[{"metadata":{"trusted":false,"_uuid":"90020a05905318b6ff2e45c26a904deefe409567"},"cell_type":"code","source":"import pandas as pd\n\ntrain = pd.read_csv(\"../input/train.csv\").as_matrix()","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"59749c90640551d5ed29093aa78881d367d797cf"},"cell_type":"code","source":"test = pd.read_csv(\"../input/test.csv\").as_matrix()","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"7e5f2be93e028db3760901183f58c1f4e4af5a27"},"cell_type":"code","source":"import numpy as np\n\nX = train[:, 1:]\nY = train[:, 0]","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"d3a7452ed90795cb4fb8472c71bab0b1affd9ca8"},"cell_type":"code","source":"from xgboost import XGBClassifier\nforest = XGBClassifier()\nforest = forest.fit(X, Y)","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"2ac57aa1dbb7fe4d2fc54f21ab1733c50a3448cb"},"cell_type":"code","source":"print(forest.score(X, Y))","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"cbe0a4f731ca8e96c88702d8840dc20ca9ea380d"},"cell_type":"code","source":"from sklearn.model_selection import cross_val_score\nscores = cross_val_score(forest, X, Y, scoring = 'accuracy', cv = 10)\nprint(scores)\nprint(scores.mean())","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"1cccde1d007b175deff4b817ed683605fb1f53a7"},"cell_type":"code","source":"prid_forest = forest.predict(test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"30f08d97b3c88ee9a6505639e6bfd63fffa1267d"},"cell_type":"code","source":"import numpy as np\nsam = pd.read_csv(\"../input/sample_submission.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"0979089e50e55ee0ad8b6e008929f3b9623edc56"},"cell_type":"code","source":"def write_prediction(prediction, name):\n    ImageId = np.array(sam['ImageId']).astype(int)\n    solution = pd.DataFrame(prediction, ImageId, columns = ['Label'])\n    solution.to_csv(name, index_label = ['ImageId'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":false,"_uuid":"a8bd2f4c5bb051db06814bace54b69338f5ea8a4"},"cell_type":"code","source":"write_prediction(prid_forest, \"Kaggle_digit_xgboost.csv\")","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}