{"cells":[{"metadata":{"_uuid":"9c11abd2-c883-484f-8943-460d37693c5e","_cell_guid":"d63d142b-60b0-4b08-b44b-4e877191d129","trusted":true},"cell_type":"code","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)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"adfa5b3a-9e3f-41c3-86c6-5aa6faab9032","_cell_guid":"e006c1b2-9357-4dc8-a466-e812ff5ee463","trusted":true},"cell_type":"code","source":"# Load dependencies\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.linear_model import LogisticRegressionCV\nfrom sklearn.metrics import roc_auc_score\nimport matplotlib.pyplot as plt\nimport pandas as pd\nimport numpy as np","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"c4386b9e-27c4-4f4b-bf35-4bd162ee2bcd","_cell_guid":"a848410f-a98b-47cf-89f3-caebb510d93e","trusted":true},"cell_type":"code","source":"train = pd.read_csv('/kaggle/input/categorical-data/train.csv')\ntest = pd.read_csv('/kaggle/input/categorical-data/test.csv')\n\nlabels = train.pop('target') \nlabels = labels.values\n\ntrain_id = train.pop(\"id\")\ntest_id = test.pop(\"id\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.shape, test.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.head(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data = pd.concat([train, test])\ndata[\"ord_5a\"] = data[\"ord_5\"].str[0]\ndata[\"ord_5b\"] = data[\"ord_5\"].str[1]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"columns = [i for i in data.columns]\n\ndummies = pd.get_dummies(data,\n                         columns=columns,\n                         drop_first=True,\n                         sparse=True)\n\ndel data","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train = dummies.iloc[:train.shape[0], :]\ntest = dummies.iloc[train.shape[0]:, :]\n\ndel dummies","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train = train.fillna(0)\ntrain.head(5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(train.shape)\nprint(test.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train = train.sparse.to_coo().tocsr()\ntest = test.sparse.to_coo().tocsr()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"lr_cv = LogisticRegressionCV(Cs=7,\n                        solver=\"lbfgs\",\n                        tol=0.0001,\n                        max_iter=30000,\n                        cv=5)\n\nlr_cv.fit(train, labels)\n\nlr_cv_pred = lr_cv.predict_proba(train)[:, 1]\nscore = roc_auc_score(labels, lr_cv_pred)\n\nprint(\"score: \", score)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"test_pred = lr_cv.predict_proba(test)[:, 1]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"submiss = pd.DataFrame({\"id\": test_id, \"target\": test_pred})\nsubmiss.to_csv('Submission(LogisticRegression).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":4}