{"cells":[{"metadata":{"_uuid":"daf4d42c611be655e7de3a2a17291dc5d3ade144"},"cell_type":"markdown","source":"Hello All !\n\nAgain back with another kaggle attempt. \n\nTaken reference from [Cats and Dogs Kernel](https://www.kaggle.com/ruchibahl18/cats-vs-dogs-basic-cnn-tutorial)\n\nUsing CNN to resolve this problem. Got a score of 0.14294. However still think rounding result might cause problem. Any suggestions welcome :)\n"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nfrom tensorflow.keras.utils import normalize\nfrom tensorflow.keras.models import Sequential\nfrom tensorflow.keras.layers import Dense, Dropout, Activation, Flatten, Conv2D, MaxPooling2D\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","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"train = pd.read_csv(\"../input/train.csv\")\ntest = pd.read_csv(\"../input/test.csv\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4220d4ee9cf2737641fb17b85d563e9a5ed1e7c9"},"cell_type":"code","source":"X = train[[col for col in train.columns if \"stop\" in col]]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5a23b7e7ca521eff0050930387510a8aee7a7ce3"},"cell_type":"code","source":"y = train[[col for col in train.columns if \"start\" in col]]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"39c40215833e6bd42078110cb8693e7a2ed33dbe"},"cell_type":"code","source":"X= np.array(X)\ny = np.array(y)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"79d0735aefb0bccefe24f57e0ac5c75032471220"},"cell_type":"markdown","source":"I have tried with skipping normalization as well adding it didn't make much difference. However normalization is an important step but in case of binary I was'nt sure"},{"metadata":{"trusted":true,"_uuid":"7b0415433bfc86e38e4eff7e2781828225d72f92"},"cell_type":"code","source":"#X = normalize(X)\n#y = normalize(y)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c74b20b1ce5ad8c5a3718e2cb7b8cd1e71f1504d"},"cell_type":"code","source":"X= X.reshape(-1, 20, 20, 1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4dc63a794a3704195893ee08ccb236ab06bbfe48"},"cell_type":"code","source":"model = Sequential()\n# Adds a densely-connected layer with 64 units to the model:\nmodel.add(Conv2D(64,(3,3), activation = 'relu', input_shape = X.shape[1:]))\nmodel.add(MaxPooling2D(pool_size = (2,2)))\n# Add another:\nmodel.add(Conv2D(64,(3,3), activation = 'relu'))\nmodel.add(MaxPooling2D(pool_size = (2,2)))\n\nmodel.add(Flatten())\nmodel.add(Dense(64, activation='relu'))\n# Add a softmax layer with 10 output units:\nmodel.add(Dense(400, activation='softmax'))\n\nmodel.compile(optimizer=\"adam\",\n              loss='binary_crossentropy',\n              metrics=['accuracy'])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"bc64a0fc9b067bd8a2e7abb215fa9a2345d731d1"},"cell_type":"code","source":"model.fit(X,y, epochs=10, batch_size=32, validation_split=0.1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"89e59f08cd550202d64e6a0b8c650640f3c04238"},"cell_type":"code","source":"test.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fc7b2a73be7376def91b0b0d47453e9d88434564"},"cell_type":"code","source":"x_test = test.drop(['id', 'delta'], axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"714d1aa53de394474668332b4674c377689d0be8"},"cell_type":"code","source":"x_test = np.array(x_test).reshape(-1,20,20,1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"59fba7d6392848ea70588b65c795cece99dfe701"},"cell_type":"code","source":"# = normalize(x_test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d355d4f3277cf16ee8ecc2cd9e4b6a5e968773b1"},"cell_type":"code","source":"predictions = model.predict(x_test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"65c7acda930c0b758b2b8f1b6a5a32d0416cb041"},"cell_type":"code","source":"#np.argmax(predictions[0][340])\n#int(round(predictions[1][0]))\npredictions = predictions.round()\npredictions = predictions.astype(int)\n#predicted_val = [int(round(p)) for p in predictions]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5b34eb3fd93cfac835505dde198ef374bd8aea81"},"cell_type":"code","source":"column_names  = ['start.'+str(i) for i in range(1,401)]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"287bfaa7a876fbe87c488fb7baa381c2dc125946"},"cell_type":"code","source":"submission = pd.DataFrame(data=predictions,    # values\n              columns=column_names)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2e40430c5dcdd966f17d226659f0413cadee25d5"},"cell_type":"code","source":"id_col = test[['id']]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7169be3ca4a62777647e4a68582612fc91c137b1"},"cell_type":"code","source":"submission['id'] = id_col","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0c2fa9bb0e6dd885d7f4debc1ea32f37d6a26a6c"},"cell_type":"code","source":"submission.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"8d0d53ea51a0cf90ea12ff07b69cef8471d04b2a"},"cell_type":"code","source":"submission.to_csv(\"submission.csv\", index = False)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"9d8dd32c9805010e6b544ef6d1a002c804ccec08"},"cell_type":"markdown","source":"That's all . However will try this example with some other way. In the meantime please provide your suggestions"},{"metadata":{"trusted":true,"_uuid":"fc2e569e147d9b072169ea0e78685094cb7c3aa2"},"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}