{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"a8e15677-d97b-595a-ab31-2f0885e13c88"},"outputs":[],"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 in \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 \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n# Any results you write to the current directory are saved as output."},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"41c66259-d475-c1a2-023e-2d1f2774f09e"},"outputs":[],"source":"%matplotlib inline\nfrom sklearn.ensemble import RandomForestClassifier\nimport numpy as np\nimport pandas as pd\n\n"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"7021e14b-c3a8-7555-e3d3-8f8543094f2a"},"outputs":[],"source":"%pwd"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"43277e76-ca6e-8e14-da3e-8a50fcc845d2"},"outputs":[],"source":"# create the training & test sets, skipping the header row with [1:]\ndataset = pd.read_csv(\"../input/train.csv\")\ntarget = dataset[[0]].values.ravel()\ntrain = dataset.iloc[:,1:].values\ntest = pd.read_csv(\"../input/test.csv\").values\n\n# create and train the random forest\n# multi-core CPUs can use: rf = RandomForestClassifier(n_estimators=100, n_jobs=2)\nrf = RandomForestClassifier(n_estimators=100)\nrf.fit(train, target)\npred = rf.predict(test)\n\nnp.savetxt('submission_rand_forest.csv', np.c_[range(1,len(test)+1),pred], delimiter=',', header = 'ImageId,Label', comments = '', fmt='%d')"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"d320f6d3-5eea-f80a-9dca-702c91ab17ec"},"outputs":[],"source":"# convert to array, specify data type, and reshape\ntarget = target.astype(np.uint8)\ntrain = np.array(train).reshape((-1, 1, 28, 28)).astype(np.uint8)\ntest = np.array(test).reshape((-1, 1, 28, 28)).astype(np.uint8)"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"99176d97-d66f-9944-ceaf-6d3ff737927a"},"outputs":[],"source":"import matplotlib.pyplot as plt\nimport matplotlib.cm as cm\n\nplt.imshow(train[1729][0], cmap=cm.binary) # draw the picture"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"3869ddd7-10e7-19b0-a9e0-fa8e8bbd244d"},"outputs":[],"source":"import lasagne\nfrom lasagne import layers\nfrom lasagne.updates import nesterov_momentum\nfrom nolearn.lasagne import NeuralNet\nfrom nolearn.lasagne import visualize\n\nnet1 = NeuralNet(\n        layers=[('input', layers.InputLayer),\n                ('hidden', layers.DenseLayer),\n                ('output', layers.DenseLayer),\n                ],\n        # layer parameters:\n        input_shape=(None,1,28,28),\n        hidden_num_units=1000, # number of units in 'hidden' layer\n        output_nonlinearity=lasagne.nonlinearities.softmax,\n        output_num_units=10,  # 10 target values for the digits 0, 1, 2, ..., 9\n\n        # optimization method:\n        update=nesterov_momentum,\n        update_learning_rate=0.0001,\n        update_momentum=0.9,\n\n        max_epochs=15,\n        verbose=1,\n        )"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"0680d7c2-04fd-72b2-69e3-893e4cdc9b6a"},"outputs":[],"source":""}],"metadata":{"_change_revision":0,"_is_fork":false,"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.5.2"}},"nbformat":4,"nbformat_minor":0}