{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Imports"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"from os import path\nfrom glob import glob\n\nimport pandas as pd\nimport numpy as np\nimport cv2\n\nfrom tqdm.notebook import tqdm\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import cross_val_score","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Read Train Data"},{"metadata":{"trusted":true},"cell_type":"code","source":"ROOT_DIR_TRAIN = '/kaggle/input/evohackaton/train/train'","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def extract_flatten_image_from_image_name(img_name, root=None):\n    if root is not None:\n        im_path = path.join(root, img_name)\n    else:\n        im_path = img_name\n    im = cv2.imread(im_path, 0)\n    im = cv2.resize(im, (32,32))\n    return im.flatten()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"train_df = pd.read_csv('/kaggle/input/evohackaton/train.csv')\ntrain_images = list(map(lambda x: extract_flatten_image_from_image_name(x, ROOT_DIR_TRAIN), train_df['name']))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train_images = np.stack(train_images).astype(float)\ntrain_labels = np.array(train_df['category'])","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Model"},{"metadata":{"trusted":true},"cell_type":"code","source":"model = LogisticRegression()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Validation"},{"metadata":{"trusted":true},"cell_type":"code","source":"val_results = cross_val_score(X=train_images, y=train_labels, estimator=model, cv=5)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Read Test Data"},{"metadata":{"trusted":true},"cell_type":"code","source":"full_image_pathes = glob('/kaggle/input/evohackaton/test/test/*.jpg')\ntest_image_names = list(map(path.basename, full_image_pathes))\n\ntest_images = list(map(extract_flatten_image_from_image_name, full_image_pathes))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_images = np.stack(test_images).astype(float)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Fit Predict"},{"metadata":{"trusted":true},"cell_type":"code","source":"model.fit(train_images, train_labels)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"y_test_hat = model.predict(test_images)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Create submission DF"},{"metadata":{"trusted":true},"cell_type":"code","source":"submission_df = pd.DataFrame({\n    'name':test_image_names,\n    'category':y_test_hat\n})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submission_df.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}