{"cells":[{"cell_type":"markdown","metadata":{"_cell_guid":"0600f5d2-97e4-69c6-491b-d427a2b45a3f"},"source":"Simple Logisitc Regression Model"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"36dbd81b-65a7-e6bc-c8b7-c9e96535ee65"},"outputs":[],"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)\nfrom sklearn.linear_model import LogisticRegression\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\nfrom subprocess import check_output\nprint(check_output([\"ls\", \"../input\"]).decode(\"utf8\"))\n\n# Any results you write to the current directory are saved as output.\n"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"716103cb-b20d-475c-3e72-32a86462a1b7"},"outputs":[],"source":"train = pd.read_csv('../input/train.csv')\nprint (train.shape)\nTRAIN_LIMIT = train.shape[0]*4/5\ny_ = train.iloc[:,0]\nx = (train.iloc[:,1:]-255/2.0)/255.0\ndef randomize(x, y):\n    shuffle = np.random.permutation(x.shape[0])\n    shuffled_x = x.iloc[shuffle]\n    shuffled_y = y.iloc[shuffle]\n    return shuffled_x, shuffled_y\nx, y = randomize(x, y_)\nx_train = x.values[:TRAIN_LIMIT]\ny_train = y.values[:TRAIN_LIMIT]\nx_validation = x.values[TRAIN_LIMIT:]\ny_validation = y.values[TRAIN_LIMIT:]"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"91b27269-3af4-7e81-2dd3-11e8dea21371"},"outputs":[],"source":"model = LogisticRegression(n_jobs=-1, solver='sag', max_iter=64000).fit(x_train, y_train)\nprint (model.score(x_validation, y_validation))"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"2c406e90-4930-6f17-b32a-a3d0fa942943"},"outputs":[],"source":"test = pd.read_csv('../input/test.csv')\n"},{"cell_type":"code","execution_count":null,"metadata":{"_cell_guid":"fddf82e1-cbfb-f1f6-3ebb-ab91081932af"},"outputs":[],"source":"result = model.predict(test.values)\nresult = np.c_[np.arange(1, result.shape[0]+1), result]\nx = pd.DataFrame(data=result, columns=['ImageId','Label'])\npd.DataFrame.to_csv(x, 'result.csv', index=False)"}],"metadata":{"_change_revision":0,"_is_fork":false,"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.5.2"}},"nbformat":4,"nbformat_minor":0}