{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Foreword\n\nThe original AutoKeras paper: https://arxiv.org/pdf/1806.10282.pdf\nDocumentation: https://autokeras.com/start/"},{"metadata":{},"cell_type":"markdown","source":"# Install Required Packages"},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"!pip install autokeras","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Import Libraries"},{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport matplotlib.image as mpimg\nimport seaborn as sns\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import confusion_matrix\n%matplotlib inline\nfrom autokeras.image.image_supervised import ImageClassifier\nnp.random.seed(2)\n\nimport itertools\nfrom keras.utils.np_utils import to_categorical # convert to one-hot-encoding","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Data Import"},{"metadata":{"trusted":true},"cell_type":"code","source":"train_data = pd.read_csv('/kaggle/input/Kannada-MNIST/train.csv')\ntest_data = pd.read_csv('/kaggle/input/Kannada-MNIST/test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print (train_data.shape)\ntrain_data.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print (test_data.shape)\ntest_data.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Data Preparation"},{"metadata":{"trusted":true},"cell_type":"code","source":"X_test_id = test_data['id']\ntrain_data['label'].value_counts()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"y_train = train_data['label']\nX_train = train_data.drop(['label'], axis = 1)\nX_test = test_data.drop(['id'], axis = 1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Regularization of values\nX_train = X_train/255.0\nX_test = X_test/255.0\n\n# Reshaping for an Image rather than line data.\nX_train = X_train.values.reshape(-1,28,28,1)\nX_test = X_test.values.reshape(-1,28,28,1)\n\n#y_train = to_categorical(y_train, num_classes = 10)\n\nX_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.2)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# AutoKeras Model"},{"metadata":{"trusted":true},"cell_type":"code","source":"clf = ImageClassifier(verbose=True)\nclf.fit(X_train, y_train, time_limit=3 * 60 * 60)\nclf.final_fit(X_train, y_val, X_val, y_val, retrain=True)\nY = clf.evaluate(X_val, y_val)\nprint(Y)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Make Submission"},{"metadata":{"trusted":true},"cell_type":"code","source":"preds = clf.predict(X_test)\npreds = np.argmax(preds,axis=1,out=None)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission = pd.DataFrame({\n    'id' : X_test_id,\n    'label' : preds\n})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission.to_csv('submission.csv',index=False)","execution_count":null,"outputs":[]}],"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}