{"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":"markdown","source":"### MNIST with no neural network\nThe [MNIST database of handwritten digits](http://yann.lecun.com/exdb/mnist/) consists of images that are 28 pixels in height and 28 pixels in width, for a total of 784 pixels in total, each image representing a digit from zero through nine.\nThis is a multiclass classification task and, although ostensibly a computer vision exercise and often solved using neural networks, it can also be treated as simply a dataset consisting of 784 features.\n\nHere we shall train the scikit-learn [HistGradientBoostingClassifier](https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.HistGradientBoostingClassifier.html). Note that [all classifiers in scikit-learn do multiclass classification out-of-the-box](https://scikit-learn.org/stable/modules/multiclass.html#multiclass-classification).","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"import numpy  as np\nimport pandas as pd\nfrom sklearn.ensemble import AdaBoostClassifier\n\nfrom sklearn.tree import DecisionTreeClassifier\nfrom sklearn.ensemble import HistGradientBoostingClassifier\n","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\ntrain_data = pd.read_csv('../input/digit-recognizer/train.csv')\ntest_data  = pd.read_csv('../input/digit-recognizer/test.csv')\nsample     = pd.read_csv('../input/digit-recognizer/sample_submission.csv')\n\nX_train = train_data.iloc[:,1:]\ny_train = train_data['label']\n\nclf = HistGradientBoostingClassifier().fit(X_train, y_train)\n\nsample[\"Label\"] = clf.predict(test_data)\nsample.to_csv('submission.csv',index=False)","metadata":{"execution":{"iopub.status.busy":"2022-03-16T00:35:44.698891Z","iopub.execute_input":"2022-03-16T00:35:44.700017Z","iopub.status.idle":"2022-03-16T00:38:50.119791Z","shell.execute_reply.started":"2022-03-16T00:35:44.699961Z","shell.execute_reply":"2022-03-16T00:38:50.118403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"clf.score(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-03-16T00:33:49.832696Z","iopub.execute_input":"2022-03-16T00:33:49.833043Z","iopub.status.idle":"2022-03-16T00:33:55.442696Z","shell.execute_reply.started":"2022-03-16T00:33:49.833005Z","shell.execute_reply":"2022-03-16T00:33:55.441960Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model = DecisionTreeClassifier(criterion='entropy', max_depth=1)# using criterion='entropy' could be another choice\nAdaBoost = AdaBoostClassifier(base_estimator=model, n_estimators=100, learning_rate=1)","metadata":{"execution":{"iopub.status.busy":"2022-03-16T00:40:51.259905Z","iopub.execute_input":"2022-03-16T00:40:51.260250Z","iopub.status.idle":"2022-03-16T00:40:51.264932Z","shell.execute_reply.started":"2022-03-16T00:40:51.260210Z","shell.execute_reply":"2022-03-16T00:40:51.264231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Fit the model with training data\nboostmodel = AdaBoost.fit(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-03-16T00:40:51.750183Z","iopub.execute_input":"2022-03-16T00:40:51.750491Z","iopub.status.idle":"2022-03-16T00:42:13.825270Z","shell.execute_reply.started":"2022-03-16T00:40:51.750456Z","shell.execute_reply":"2022-03-16T00:42:13.823996Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"AdaBoost.score(X_train, y_train)","metadata":{"execution":{"iopub.status.busy":"2022-03-16T00:42:13.827406Z","iopub.execute_input":"2022-03-16T00:42:13.827694Z","iopub.status.idle":"2022-03-16T00:42:27.665678Z","shell.execute_reply.started":"2022-03-16T00:42:13.827662Z","shell.execute_reply":"2022-03-16T00:42:27.664667Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}