{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nimport os\n!unzip /kaggle/input/expedia-personalized-sort/data.zip \n### ZipFile can't read this proprietary format \nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"Train=pd.read_csv(\"train.csv\")\nTest=pd.read_csv(\"test.csv\")","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":"print(Train.isnull().sum())\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print(Test.isnull().sum())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Train=Train.dropna(axis=1,how=\"any\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Train.isnull().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Train.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import seaborn as sns\ndf = Train.corr()\nprint(df)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Train[[\"promotion_flag\",\"position\"]].groupby(\"promotion_flag\").sum().position.plot(kind=\"pie\",shadow=True,autopct=\"%1.1f%%\",radius=1.2,startangle=120)\nplt.title(\"Promotion Graph\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Train=Train.drop([\"srch_id\",\"date_time\",\"site_id\",\"visitor_location_country_id\",\"prop_country_id\",\"prop_id\",\"srch_destination_id\"],axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Test=Test.dropna(axis=1,how=\"any\")","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Test.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Test=Test.drop([\"srch_id\",\"date_time\",\"site_id\",\"visitor_location_country_id\",\"prop_country_id\",\"prop_id\",\"srch_destination_id\"],axis=1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Test.columns","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Train=Train[['prop_starrating', 'prop_brand_bool', 'prop_location_score1',\n       'prop_log_historical_price', 'price_usd', 'promotion_flag',\n       'srch_length_of_stay', 'srch_booking_window', 'srch_adults_count',\n       'srch_children_count', 'srch_room_count', 'srch_saturday_night_bool',\n       'random_bool']]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from sklearn.cluster import KMeans\ndata = Train\nn_cluster = range(1,11)\n\nkmeans = [KMeans(n_clusters = i).fit(data) for i in n_cluster]\nscores = [kmeans[i].score(data) for i in range(len(kmeans))]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(10,5))\nsns.lineplot(range(1, 11), scores,marker='o',color='red')\nplt.title('The Elbow Method')\nplt.xlabel('Number of clusters')\nplt.ylabel('WCSS')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from sklearn.cluster import KMeans\nkm = KMeans(n_clusters = 8)\nkmean=km.fit(Train)\ny_kmeans = km.predict(Train)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from mpl_toolkits.mplot3d import Axes3D\nimport numpy as np\nfig = plt.figure(1, figsize = (7, 7))\n\nax = Axes3D(fig, rect = [0, 0, 0.95, 1], \n            elev = 48, azim = 134)\n\nax.scatter(Train.iloc[:, 4:5],\n           Train.iloc[:, 7:8], \n           Train.iloc[:, 11:12],\n           c = km.labels_.astype(np.float), edgecolor = 'm')\n\nax.set_xlabel('USD')\nax.set_ylabel('srch_booking_window')\nax.set_zlabel('srch_saturday_night_bool')\n\nplt.title('K Means', fontsize = 10)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"km.predict(Test)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","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}