{"cells":[{"metadata":{"trusted":true,"_uuid":"3efcb14c6d6c83cab11ae849b61b016c852807ee"},"cell_type":"code","source":"# Package imports\nimport numpy as np\nimport pandas as pd\nimport lightgbm\nfrom sklearn.model_selection import train_test_split\nfrom sklearn.preprocessing import LabelBinarizer\n\nimport warnings\nwarnings.filterwarnings(\"ignore\")","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"056473b3c835b488735b3c2bb9edf2fe74af6ce6","trusted":true,"scrolled":true},"cell_type":"code","source":"train = pd.read_csv(\"../input/train.csv\")\ntest = pd.read_csv(\"../input/test.csv\")\n\nX = train[[\"bone_length\", \"rotting_flesh\", \"hair_length\", \"has_soul\"]]\nY, Y_label= pd.factorize(train['type'])\nX_pred  = test.drop([\"id\", \"color\"], axis=1)\nY = pd.DataFrame(Y)\nY.columns = ['type']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d88be375b1326802a4d3e67165beebc8a4c1ab17"},"cell_type":"code","source":"#제일 큰 컬럼 인덱스 찾기\nX['max_feature'] = X.iloc[:,0:4].idxmax(axis=1)\nX['min_feature'] = X.iloc[:,0:4].idxmin(axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"b48ac0b202533132f3777291eff5ae4b47ae186d"},"cell_type":"code","source":"#X['max-min'] = X.iloc[:,0:3].max(axis=1)-X.iloc[:,0:3].min(axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e9b93e5e9f8ef1a1fa23e3986ef890aabd061308"},"cell_type":"code","source":"#X.sort_values(\"max-min\", ascending=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c8d80e84f9d5b68d2bc81f0add986ee3c3e06e29","collapsed":true},"cell_type":"code","source":"#X['max_feature'] == 'rotting_flesh' and X['min_feature'] == 'has_soul'\nX[(X.max_feature == 'rotting_flesh')&(X.min_feature == 'has_soul')]\n#df1 = df[(df.a != -1) & (df.b != -1)]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"ed2d550bd01b1ca28609bd45b40f1de6d78038a5"},"cell_type":"code","source":"X['isGoast'] = np.where((X.max_feature == 'rotting_flesh')&(X.min_feature == 'has_soul'), 1, 0)\n#df['color'] = np.where(df['Set']=='Z', 'green', 'red')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"304c316c336fa08b9424c647a792d5fe03d6db0d"},"cell_type":"code","source":"X.drop(columns=[\"max_feature\", \"min_feature\"], inplace=True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"90fc264e83b54ccaeaaabd82a5ea8efc988c90a6"},"cell_type":"code","source":"X, X_test = train_test_split(X, test_size=0.2, random_state=42)\nY, Y_test = train_test_split(Y, test_size=0.2, random_state=42)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e726c582cbd9a284c73ccdcedcaa806525336065"},"cell_type":"code","source":"train_data = lightgbm.Dataset(X, label=Y)\ntest_data  = lightgbm.Dataset(X_test, label=Y_test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"365c2124fefdc3d82d2dd2c633b5a8d1a7996da9"},"cell_type":"code","source":"parameters = {\n    'application': 'multiclass',\n    'objective': 'multiclass',\n    'num_class':3,\n    'metric': 'multi_logloss',\n    'boosting': 'dart',\n    #'boosting': 'rf',\n    'num_leaves': 50,\n    'feature_fraction': 0.5,\n    'bagging_fraction': 0.5,\n    'bagging_freq': 20,\n    'learning_rate': 0.001,\n    'max_depth' : 6\n}","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c427537114b989c02c194733a7d1cf14d399c55e"},"cell_type":"code","source":"model = lightgbm.train(parameters,\n                       train_data,\n                       valid_sets=test_data,\n                       num_boost_round=5000,\n                       early_stopping_rounds=500)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"f69075d137bbd6f3ee9844aece48238095a6d114"},"cell_type":"code","source":"prediction = model.predict(X_pred)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"0a0188213c9437d64ab3c57a2e785b2c4d41c2e1"},"cell_type":"code","source":"prediction = Y_label[np.argmax(prediction, axis=1)]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"1be35e9c2cad86c9f3d42bfc5c3b967695f201fe"},"cell_type":"code","source":"submission = pd.DataFrame(prediction)\nsubmission.columns = [\"type\"]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fe1ff6ab0d6abf4b75cd26af97e10d4736f78fa3"},"cell_type":"code","source":"submission = pd.concat([test['id'], submission[\"type\"]], axis=1)\nsubmission.to_csv(\"submission_lightGBM.csv\", index=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"5b4974036af4120594d64e4e4a09df7975bd58ec"},"cell_type":"code","source":"submission","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"55eabdf7aac4cfc8c422633a489bc17e78ed623d"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"hide_input":false,"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"},"toc":{"base_numbering":1,"nav_menu":{},"number_sections":true,"sideBar":true,"skip_h1_title":false,"title_cell":"Table of Contents","title_sidebar":"Contents","toc_cell":false,"toc_position":{},"toc_section_display":true,"toc_window_display":false},"varInspector":{"cols":{"lenName":16,"lenType":16,"lenVar":40},"kernels_config":{"python":{"delete_cmd_postfix":"","delete_cmd_prefix":"del ","library":"var_list.py","varRefreshCmd":"print(var_dic_list())"},"r":{"delete_cmd_postfix":") ","delete_cmd_prefix":"rm(","library":"var_list.r","varRefreshCmd":"cat(var_dic_list()) "}},"types_to_exclude":["module","function","builtin_function_or_method","instance","_Feature"],"window_display":false}},"nbformat":4,"nbformat_minor":1}