{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np \nimport pandas as pd \nfrom sklearn.linear_model import LogisticRegression, SGDClassifier\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.metrics import f1_score, accuracy_score\nimport matplotlib.pyplot as plt\nfrom matplotlib.colors import ListedColormap\nfrom sklearn.ensemble import BaggingClassifier\nfrom keras.callbacks import LearningRateScheduler","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"# Вы можете тестить свои алгоритмы прямо на kaggle, данные здесь уже есть, их нужно только загрузить\ntrain_x = pd.read_csv('../input/bird-or-aircraft-2020/train_x.csv', index_col=0, header=None)\ntrain_y = pd.read_csv('../input/bird-or-aircraft-2020/train_y.csv', index_col=0)\ntest_x = pd.read_csv('../input/bird-or-aircraft-2020/test_x.csv', index_col=0, header=None)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Этот блок был бы нужен, если бы у нас классы назывались 'Bird' и 'Airplane'\n# mappping_type = {'Bird': 0, 'Airplane': 1}\n# train_y = train_y.replace({\"target\": mappping_type})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# в train_y у нас лежат лейблы (птиццы и самолеты = 0 и 1)\ntrain_y","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# 7200 картинок 32х32х3\ntrain_x","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# посмотрим на картинки\n_train_x = train_x.values.reshape(7200,32,32,3)\n_test_x = test_x.values.reshape(4800,32,32,3)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"i = np.random.randint(7200)\nprint(train_y.iloc[i])\nplt.imshow(_train_x[i])\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# нормируем данные, этого можно и не делать, почему?\ntrain_feature_matrix, test_feature_matrix = train_x/255, test_x/255","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# здесь должен быть ваш классификатор\nclf = SGDClassifier(max_iter=1000, tol=1e-3, loss='log', penalty='l2')\nclf.fit(train_feature_matrix, np.ravel(train_y))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"accuracy_score(clf.predict(train_feature_matrix), np.ravel(train_y)) # np.ravel - разворачиваем массив в строку","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"predict_y = clf.predict_proba(test_x)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# это можно не менять, просто упаковываются данные в csv\nsample = pd.DataFrame(np.array([[i, x.argmax()] for i, x in enumerate(predict_y)]), columns=['id', 'target'])\n\n# mappping_type_inv = {0: 'Bird', 1: 'Airplane'}\n# sample = sample.replace({'target': mappping_type_inv})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sample.to_csv('submit.csv', index=False)\n# на этом месте формируется ответ в виде файла submit.csv на kaggle,\n# вы должны сделать commit своего кернела, а затем перейти в раздел data и нажать submit to competition","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}