File size: 3,142 Bytes
0a58a6f
1
2
{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"id":"LI8PnFZ9CY8D"},"outputs":[],"source":["import pandas as pd\n","from pandas import Series, DataFrame\n","import numpy as np\n","import matplotlib.pyplot as plt\n","from sklearn.ensemble import RandomForestClassifier\n","\n","\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"QC0uRmQSCsQq"},"outputs":[],"source":["train = pd.read_excel(\"input/washer_분석용 데이터.xls\")"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"YAKgHScREYiq"},"outputs":[],"source":["train = pd.read_excel(\"input/washer_분석용 데이터.xls\", sheet_name=1)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"D9XGKYmRCsJC"},"outputs":[],"source":["train = train.iloc[:, :-3]\n","\n","train"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"S8Vamo80Ezg5"},"outputs":[],"source":["X_train = train.drop(\"BrandSwitching\",axis=1)\n","Y_train = train[\"BrandSwitching\"]\n","\n","rf_model = RandomForestClassifier(n_estimators=100, random_state=42)\n","rf_model.fit(X_train, Y_train)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"6nG25KUcGPhU"},"outputs":[],"source":["Y_pred = rf_model.predict(X_train)\n","Y_pro = rf_model.predict_proba(X_train)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"WscFuv3mHFay"},"outputs":[],"source":["Y_pred"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"FNUoUdQIHHxE"},"outputs":[],"source":["Y_pro"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"j3RMG-rOHI-g"},"outputs":[],"source":["rf_model.score(X_train, Y_train)"]},{"cell_type":"markdown","metadata":{"id":"7efD-9JFyI3l"},"source":["------------------------------"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"IWfkVklVq51d"},"outputs":[],"source":["train_half = train.iloc[40:80]\n","test_half = train"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"0gOTWYblrGXV"},"outputs":[],"source":["X_train2 = train_half.drop(\"BrandSwitching\",axis=1)\n","Y_train2 = train_half[\"BrandSwitching\"]\n","X_test2 = test_half.drop(\"BrandSwitching\",axis=1)\n","Y_test2 = test_half[\"BrandSwitching\"]\n","\n","rf_model = RandomForestClassifier(n_estimators=100, random_state=42)\n","rf_model.fit(X_train2, Y_train2)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"bpZmkSFruY4C"},"outputs":[],"source":["Y_pred2 = rf_model.predict(X_test2)\n","Y_pro2 = rf_model.predict_proba(X_test2)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"HQLpw4KAui14"},"outputs":[],"source":["a_1 = 0\n","for i in range(0,len(Y_pred2)):\n","    if Y_pred2[i] != Y_test2[i]:\n","        a_1+=1\n","print('Discord', a_1)\n","\n","print(\"discord rate:\",round(a_1/len(Y_pred2)*100, 2),\"%\")"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"NI2oy_xYvTtC"},"outputs":[],"source":["Y_pred2"]}],"metadata":{"colab":{"authorship_tag":"ABX9TyNJYIKxXolmheRpHQROsFoF","private_outputs":true,"provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0}