{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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 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\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","collapsed":true,"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"data_all = pd.read_csv('../input/train.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"590947976eb3a655f66e6e0a836a6584d6f4db04"},"cell_type":"code","source":"data = data_all.drop(columns = ['label'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a7999d255bb666e1ec972105bc56a83c171494fa"},"cell_type":"code","source":"from keras.utils import np_utils\n\ndata_labels = np_utils.to_categorical(np.array(data_all['label']), 10) ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"98b46972c4e6cc83730de82942d4fe51af75d1c4"},"cell_type":"code","source":"data = data.values","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"55059df8ec2948e02fd9fe610667c4c26b901e94"},"cell_type":"code","source":"import tensorflow as tf\nimport tflearn\n\n# Define the neural network\n\n\ndef build_model():\n    # This resets all parameters and variables, leave this here\n    tf.reset_default_graph()\n    \n    # Inputs\n    net = tflearn.input_data([None, data.shape[1]])\n\n    # Hidden layer(s)\n    net = tflearn.fully_connected(net, 128, activation='ReLU')\n    net = tflearn.fully_connected(net, 32, activation='ReLU')\n    \n    # Output layer and training model\n    net = tflearn.fully_connected(net, 10, activation='softmax')\n    net = tflearn.regression(net, optimizer='sgd', learning_rate=0.01, loss='categorical_crossentropy')\n    \n    model = tflearn.DNN(net)\n    return model\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"62ac1edfa315ca566afce85fbd4df0f1a26c05f1"},"cell_type":"code","source":"model = build_model()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0a3481bb0d907ab31d3cdd16cb07778c6f49b656"},"cell_type":"code","source":"model.fit(data, data_labels, validation_set=0.1, show_metric=True, batch_size=100, n_epoch=20)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"c0c70becde093708b17354c4e32db1f5e4a31c3c"},"cell_type":"code","source":"data_test = pd.read_csv('../input/test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"59c8e750b321731cfbd1b7a53c9c44aabb826972"},"cell_type":"code","source":"predictions = np.array(model.predict(data_test.values)).argmax(axis=1)\n\nsubmission = pd.DataFrame({ 'ImageId': list(range(1,len(predictions)+1)), 'Label': predictions})\nsubmission.to_csv('submission.csv', index=False)\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"275f6b24f50707d47d72e8e20f4c4a5c23dc9b14"},"cell_type":"code","source":"","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}