diff --git a/Airlinepassengerreferral_predicton__1_.ipynb b/Airlinepassengerreferral_predicton__1_.ipynb index 187d0c57ec2f354790941fdd1e6e0c0c0893d8a4..d8c07394d71277eac6eb7a60e3e35134518e453e 100644 --- a/Airlinepassengerreferral_predicton__1_.ipynb +++ b/Airlinepassengerreferral_predicton__1_.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": 115, + "execution_count": null, "metadata": { "id": "xI1O-udM7sJj" }, @@ -52,13 +52,15 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "id": "wz7IlGTZS6Nw" + }, "outputs": [], "source": [] }, { "cell_type": "code", - "execution_count": 232, + "execution_count": null, "metadata": { "id": "5O2Is-Q772Lh" }, @@ -78,7 +80,7 @@ }, { "cell_type": "code", - "execution_count": 233, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -281,7 +283,7 @@ }, { "cell_type": "code", - "execution_count": 234, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -477,7 +479,7 @@ }, { "cell_type": "code", - "execution_count": 235, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -503,7 +505,7 @@ }, { "cell_type": "code", - "execution_count": 236, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -533,7 +535,7 @@ }, { "cell_type": "code", - "execution_count": 237, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -576,7 +578,7 @@ }, { "cell_type": "code", - "execution_count": 238, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -622,7 +624,7 @@ }, { "cell_type": "code", - "execution_count": 239, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -780,7 +782,7 @@ }, { "cell_type": "code", - "execution_count": 240, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -823,7 +825,7 @@ }, { "cell_type": "code", - "execution_count": 241, + "execution_count": null, "metadata": { "id": "p5IU6nNYQwfg" }, @@ -853,7 +855,7 @@ }, { "cell_type": "code", - "execution_count": 242, + "execution_count": null, "metadata": { "id": "jos6N2yhQ5yz" }, @@ -887,7 +889,7 @@ }, { "cell_type": "code", - "execution_count": 127, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -914,7 +916,7 @@ }, { "cell_type": "code", - "execution_count": 128, + "execution_count": null, "metadata": { "id": "Gt5N46PWRZDx" }, @@ -939,7 +941,7 @@ }, { "cell_type": "code", - "execution_count": 129, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -975,7 +977,7 @@ }, { "cell_type": "code", - "execution_count": 132, + "execution_count": null, "metadata": { "id": "Xvlrzz4VTxXw" }, @@ -986,7 +988,7 @@ }, { "cell_type": "code", - "execution_count": 133, + "execution_count": null, "metadata": { "id": "mVYxrShFR0A2" }, @@ -1009,7 +1011,7 @@ }, { "cell_type": "code", - "execution_count": 134, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -1054,7 +1056,7 @@ }, { "cell_type": "code", - "execution_count": 245, + "execution_count": null, "metadata": { "id": "NO-AVUrNSF76" }, @@ -1065,7 +1067,7 @@ }, { "cell_type": "code", - "execution_count": 246, + "execution_count": null, "metadata": { "id": "bXS94JOMUu-r" }, @@ -1076,7 +1078,7 @@ }, { "cell_type": "code", - "execution_count": 247, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -1115,7 +1117,7 @@ }, { "cell_type": "code", - "execution_count": 248, + "execution_count": null, "metadata": { "id": "6nNZ2T2VRbXO" }, @@ -1127,7 +1129,7 @@ }, { "cell_type": "code", - "execution_count": 249, + "execution_count": null, "metadata": { "id": "tT04SGgTU4BI" }, @@ -1138,7 +1140,7 @@ }, { "cell_type": "code", - "execution_count": 250, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -1186,7 +1188,7 @@ }, { "cell_type": "code", - "execution_count": 251, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -1237,7 +1239,7 @@ }, { "cell_type": "code", - "execution_count": 252, + "execution_count": null, "metadata": { "id": "tQN7gZhOW9nO" }, @@ -1248,7 +1250,7 @@ }, { "cell_type": "code", - "execution_count": 253, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -1357,7 +1359,7 @@ }, { "cell_type": "code", - "execution_count": 243, + "execution_count": null, "metadata": { "id": "BxDfAo9lKAFS", "outputId": "61329e86-0f5a-4950-d5e0-36f63afc3c6f" @@ -1385,7 +1387,7 @@ }, { "cell_type": "code", - "execution_count": 145, + "execution_count": null, "metadata": { "id": "8Q68S13iKAFS", "outputId": "30ddf4fe-9e66-4c41-a29b-b0408adda5f8" @@ -1420,7 +1422,7 @@ }, { "cell_type": "code", - "execution_count": 254, + "execution_count": null, "metadata": { "id": "nJhc3zaPKAFS", "outputId": "36c2536e-d5d7-4926-ffbb-f7f8a441841d" @@ -1480,7 +1482,7 @@ }, { "cell_type": "code", - "execution_count": 148, + "execution_count": null, "metadata": { "id": "CV5g7Vp0KAFT", "outputId": "9ae286b0-2701-4944-dd6a-1df953d3639b" @@ -1511,7 +1513,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "4CzDU-jIS6N6" + }, "source": [ "* So, economy class have more recomandation and first class have minimum.\n" ] @@ -1528,7 +1532,7 @@ }, { "cell_type": "code", - "execution_count": 149, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -1566,7 +1570,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "2bZZsNbFS6N7" + }, "source": [ "The bar plot shows the count of reviews categorized by traveler type (Business, Family Leisure, Solo Leisure, Couple Leisure). Here's what the graph suggests:\n", "\n", @@ -1600,7 +1606,7 @@ }, { "cell_type": "code", - "execution_count": 150, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -1637,7 +1643,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "ZAYwYB7rS6N8" + }, "source": [ "This graph shows maximum trips by planes . British airways has the most." ] @@ -1653,7 +1661,7 @@ }, { "cell_type": "code", - "execution_count": 151, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -1685,7 +1693,7 @@ }, { "cell_type": "code", - "execution_count": 228, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -1739,7 +1747,7 @@ }, { "cell_type": "code", - "execution_count": 153, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -1770,15 +1778,17 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "H8ImLkRRS6N9" + }, "source": [ - "* As we have seen earlier 'British Airways' is the topmost Airline. \n", + "* As we have seen earlier 'British Airways' is the topmost Airline.\n", "* 'Tunisair','Germanwings' etc are the lowest number of trips." ] }, { "cell_type": "code", - "execution_count": 154, + "execution_count": null, "metadata": { "id": "rE-4TENmin-P" }, @@ -1790,7 +1800,7 @@ }, { "cell_type": "code", - "execution_count": 155, + "execution_count": null, "metadata": { "id": "N5ANZppMfsKq" }, @@ -1810,7 +1820,7 @@ }, { "cell_type": "code", - "execution_count": 156, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -1842,7 +1852,9 @@ }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "id": "weOxkRcKS6N-" + }, "source": [ "Correlation matrix heatmap, which illustrates the relationships between different aspects of airline services, such as seat comfort, cabin service, food and beverages, entertainment, ground service, value for money, and how these factors correlate with overall customer satisfaction and recommendation rates.\n", "\n", @@ -1866,7 +1878,7 @@ }, { "cell_type": "code", - "execution_count": 157, + "execution_count": null, "metadata": { "id": "94xRV2gKjXPo" }, @@ -1877,7 +1889,7 @@ }, { "cell_type": "code", - "execution_count": 158, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -1906,7 +1918,7 @@ }, { "cell_type": "code", - "execution_count": 159, + "execution_count": null, "metadata": { "id": "8T6q-4DM79HM" }, @@ -1926,7 +1938,7 @@ }, { "cell_type": "code", - "execution_count": 160, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", @@ -2103,7 +2115,7 @@ }, { "cell_type": "code", - "execution_count": 161, + "execution_count": null, "metadata": { "id": "bGT9lH07Jslz" }, @@ -2125,7 +2137,7 @@ }, { "cell_type": "code", - "execution_count": 162, + "execution_count": null, "metadata": { "id": "wYLkkdmxJ6ZE" }, @@ -2151,9 +2163,10 @@ }, { "cell_type": "code", - "execution_count": 163, + "execution_count": null, "metadata": { - "id": "C2WHHqiRDD_r" + "id": "C2WHHqiRDD_r", + "outputId": "eaf7cf23-ec3d-458f-9b37-7ff67593cf36" }, "outputs": [ { @@ -2176,7 +2189,7 @@ }, { "cell_type": "code", - "execution_count": 164, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -2202,7 +2215,7 @@ }, { "cell_type": "code", - "execution_count": 165, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -2228,7 +2241,7 @@ }, { "cell_type": "code", - "execution_count": 166, + "execution_count": null, "metadata": { "id": "nJ9rTJjYHvJv" }, @@ -2240,7 +2253,7 @@ }, { "cell_type": "code", - "execution_count": 167, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -2267,18 +2280,14 @@ "cell_type": "code", "execution_count": null, "metadata": { - "colab": { - "base_uri": "https://localhost:8080/" - }, - "id": "FLwVC70GH528", - "outputId": "7b8b329b-250f-4cfb-cb37-35e49bf7190e" + "id": "FLwVC70GH528" }, "outputs": [], "source": [] }, { "cell_type": "code", - "execution_count": 168, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -2324,7 +2333,7 @@ }, { "cell_type": "code", - "execution_count": 169, + "execution_count": null, "metadata": { "id": "kULpJOi8H8Sx" }, @@ -2337,7 +2346,7 @@ }, { "cell_type": "code", - "execution_count": 170, + "execution_count": null, "metadata": { "id": "cQbmgg_ZIHD3" }, @@ -2366,9 +2375,10 @@ }, { "cell_type": "code", - "execution_count": 171, + "execution_count": null, "metadata": { - "id": "ANv9nzxoh9Nk" + "id": "ANv9nzxoh9Nk", + "outputId": "f86f6d15-9cfc-435d-81a7-cc4ce1897726" }, "outputs": [ { @@ -2393,7 +2403,7 @@ }, { "cell_type": "code", - "execution_count": 172, + "execution_count": null, "metadata": { "id": "b235fa57", "outputId": "dbeba9ca-8145-4516-a3d8-2d66e8587c5f", @@ -2416,7 +2426,7 @@ }, { "cell_type": "code", - "execution_count": 173, + "execution_count": null, "metadata": { "id": "ab8bfa30", "outputId": "f0b726bd-92fe-4f09-8acb-fc857cd35af7", @@ -2443,7 +2453,7 @@ }, { "cell_type": "code", - "execution_count": 174, + "execution_count": null, "metadata": { "id": "33629d40" }, @@ -2455,7 +2465,7 @@ }, { "cell_type": "code", - "execution_count": 175, + "execution_count": null, "metadata": { "id": "b424a17b", "outputId": "2486b767-d83f-4e1e-a35e-5a6eb55a0922" @@ -2498,7 +2508,7 @@ }, { "cell_type": "code", - "execution_count": 176, + "execution_count": null, "metadata": { "id": "1f18bc90", "outputId": "1a49b7c0-2fda-451f-bd6c-4868fa41fd99" @@ -2524,7 +2534,7 @@ }, { "cell_type": "code", - "execution_count": 177, + "execution_count": null, "metadata": { "id": "d0505bf0", "outputId": "ab3c3433-5864-4b51-ae80-ab40560d62ac" @@ -2547,7 +2557,7 @@ }, { "cell_type": "code", - "execution_count": 178, + "execution_count": null, "metadata": { "id": "d4af37e2", "outputId": "d571539f-3e83-44d1-8271-19d570f77915" @@ -2578,8 +2588,10 @@ }, { "cell_type": "code", - "execution_count": 256, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "ePmCbKZfS6OF" + }, "outputs": [], "source": [ "Y_pred_tree = tree_classify.predict(X_test)\n", @@ -2588,7 +2600,7 @@ }, { "cell_type": "code", - "execution_count": 179, + "execution_count": null, "metadata": { "id": "40e897f8", "outputId": "1b4cf01c-00d9-4417-d7a2-9f1610355dd8" @@ -2619,8 +2631,11 @@ }, { "cell_type": "code", - "execution_count": 180, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "GvFc6gOCS6OG", + "outputId": "71302171-ee3f-488c-dd42-fd12bd2cd14f" + }, "outputs": [ { "name": "stdout", @@ -2651,8 +2666,10 @@ }, { "cell_type": "code", - "execution_count": 181, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "awnXzmfyS6OG" + }, "outputs": [], "source": [ "metrics_df = add_metrics_details(\"Decision Tree Model\", Y_test, Y_pred, metrics_df)" @@ -2669,7 +2686,7 @@ }, { "cell_type": "code", - "execution_count": 182, + "execution_count": null, "metadata": { "id": "eed30370", "outputId": "dd496ed7-40d8-43fe-89ac-37f78f6dd762" @@ -2697,7 +2714,7 @@ }, { "cell_type": "code", - "execution_count": 183, + "execution_count": null, "metadata": { "id": "5371acc9", "outputId": "9b4391ef-d576-47ae-dbb3-116391332514" @@ -2719,9 +2736,10 @@ }, { "cell_type": "code", - "execution_count": 184, + "execution_count": null, "metadata": { - "id": "545ac715" + "id": "545ac715", + "outputId": "aacd46a4-747c-49a4-a87a-87bf3781f9bc" }, "outputs": [ { @@ -2744,10 +2762,9 @@ }, { "cell_type": "code", - "execution_count": 185, + "execution_count": null, "metadata": { - "id": "c9443b7b", - "outputId": "09c20dd7-7e4d-4407-d1a9-9d23a80f418a" + "id": "c9443b7b" }, "outputs": [], "source": [ @@ -2758,7 +2775,7 @@ }, { "cell_type": "code", - "execution_count": 186, + "execution_count": null, "metadata": { "id": "dc7a01e5", "outputId": "2cc84915-7e2a-4c8c-cb66-d7249a873006" @@ -2800,9 +2817,10 @@ }, { "cell_type": "code", - "execution_count": 187, + "execution_count": null, "metadata": { - "id": "487d5448" + "id": "487d5448", + "outputId": "b94cf1ba-9543-481d-e277-c579ff4cefc5" }, "outputs": [ { @@ -2822,8 +2840,11 @@ }, { "cell_type": "code", - "execution_count": 188, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "W27rY6ccS6OH", + "outputId": "08d3141a-ca8d-4d03-8dd3-68fba295e9b7" + }, "outputs": [ { "data": { @@ -2842,8 +2863,11 @@ }, { "cell_type": "code", - "execution_count": 189, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "KI1YLu5bS6OI", + "outputId": "4875dc4e-616d-4aad-8189-03bcec9327b4" + }, "outputs": [ { "data": { @@ -2866,8 +2890,11 @@ }, { "cell_type": "code", - "execution_count": 190, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "3nzBCwpZS6OI", + "outputId": "d594e6c3-4913-4ead-c3f8-1ee5f4fd0df7" + }, "outputs": [ { "name": "stdout", @@ -2893,8 +2920,10 @@ }, { "cell_type": "code", - "execution_count": 257, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "BS_1G24LS6OI" + }, "outputs": [], "source": [ "Y_pred_knn = knn_classify.predict(X_test)\n", @@ -2903,8 +2932,11 @@ }, { "cell_type": "code", - "execution_count": 191, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "9PYQW1sJS6OI", + "outputId": "21f762ee-929f-46b7-9723-8f8c411ff2e9" + }, "outputs": [ { "name": "stdout", @@ -2935,8 +2967,10 @@ }, { "cell_type": "code", - "execution_count": 192, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "RF7V-j_yS6OJ" + }, "outputs": [], "source": [ "metrics_df = add_metrics_details(\"KNN Model\", Y_test, Y_pred, metrics_df)" @@ -2953,7 +2987,7 @@ }, { "cell_type": "code", - "execution_count": 259, + "execution_count": null, "metadata": { "id": "e0f3952f", "outputId": "19a0bf12-4e8f-428c-e89a-5910214e57b4" @@ -2982,8 +3016,11 @@ }, { "cell_type": "code", - "execution_count": 194, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "oX78sbkGS6OJ", + "outputId": "553f2f3f-185c-4170-94c8-5b1376584e4f" + }, "outputs": [ { "name": "stdout", @@ -3002,8 +3039,11 @@ }, { "cell_type": "code", - "execution_count": 195, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "RYC1C7xCS6OJ", + "outputId": "525b3cfd-952a-4a4b-88ff-e9b6528eeb41" + }, "outputs": [ { "name": "stdout", @@ -3025,8 +3065,11 @@ }, { "cell_type": "code", - "execution_count": 196, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "-BA3Sgs4S6OK", + "outputId": "e314985a-f9c7-41d6-e5f3-30ecc831ac3c" + }, "outputs": [ { "data": { @@ -3060,8 +3103,11 @@ }, { "cell_type": "code", - "execution_count": 197, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "0zClFEJUS6OK", + "outputId": "bba4f5eb-06e9-4272-84fc-c15428613bf2" + }, "outputs": [ { "name": "stdout", @@ -3081,8 +3127,11 @@ }, { "cell_type": "code", - "execution_count": 198, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "beDs3TwNS6OK", + "outputId": "ed3dea6a-c039-44dc-ae4b-5aadca7454ba" + }, "outputs": [ { "data": { @@ -3106,7 +3155,7 @@ }, { "cell_type": "code", - "execution_count": 199, + "execution_count": null, "metadata": { "id": "919bf13d", "outputId": "9e0b8e70-3ea0-4cd9-9c32-b8657ad993a1" @@ -3136,8 +3185,10 @@ }, { "cell_type": "code", - "execution_count": 260, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "wCE00a0SS6OL" + }, "outputs": [], "source": [ "Y_pred_svm = svm_model.predict(X_test)\n", @@ -3146,8 +3197,11 @@ }, { "cell_type": "code", - "execution_count": 200, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "jRhDJr9RS6OL", + "outputId": "9f76bbb4-434f-4513-ead4-b85226ac2f9e" + }, "outputs": [ { "data": { @@ -3171,8 +3225,11 @@ }, { "cell_type": "code", - "execution_count": 201, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "XEU8o_w4S6OL", + "outputId": "a78ebac7-bf14-4d63-b69e-36cae258f358" + }, "outputs": [ { "name": "stdout", @@ -3193,8 +3250,11 @@ }, { "cell_type": "code", - "execution_count": 261, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "bLyaLcpsS6OL", + "outputId": "5d8ce848-5ef6-4a42-b2ae-37e559356017" + }, "outputs": [ { "data": { @@ -3236,8 +3296,11 @@ }, { "cell_type": "code", - "execution_count": 202, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "Tj9z8YrHS6OM", + "outputId": "dca83d84-b37e-4f86-ebfd-4134ca0f4a0c" + }, "outputs": [ { "name": "stdout", @@ -3296,8 +3359,11 @@ }, { "cell_type": "code", - "execution_count": 215, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "FjrYsCFoS6OM", + "outputId": "a12d2dc5-4986-46b0-b234-496810a4c7e7" + }, "outputs": [ { "data": { @@ -3461,8 +3527,11 @@ }, { "cell_type": "code", - "execution_count": 203, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "jQ0zzcoQS6OM", + "outputId": "962c6a24-2c9c-49bf-c706-6d5336ab914e" + }, "outputs": [ { "name": "stdout", @@ -3484,9 +3553,18 @@ ] }, { - "cell_type": "code", - "execution_count": 205, + "cell_type": "markdown", "metadata": {}, + "source": [ + "# Q learning" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "sHCGJZHGS6ON" + }, "outputs": [], "source": [ "# Load the dataset\n", @@ -3498,15 +3576,17 @@ "numerical_features = ['overall', 'seat_comfort', 'cabin_service', 'food_bev', 'entertainment', 'ground_service', 'value_for_money']\n", "dataset[numerical_features] = scaler.fit_transform(dataset[numerical_features])\n", "\n", - "# Convert boolean features to integers\n", + "\n", "boolean_features = ['Couple Leisure', 'Family Leisure', 'Solo Leisure', 'Economy Class', 'First Class', 'Premium Economy']\n", "dataset[boolean_features] = dataset[boolean_features].astype(int)" ] }, { "cell_type": "code", - "execution_count": 206, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "dQdJ9gKxS6ON" + }, "outputs": [], "source": [ "# Define states and actions\n", @@ -3520,28 +3600,33 @@ }, { "cell_type": "code", - "execution_count": 207, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "L-dVzpcYS6ON" + }, "outputs": [], "source": [ "# Hyperparameters\n", "alpha = 0.1\n", "gamma = 0.95\n", "epsilon = 0.1\n", - "num_episodes = 10000\n", + "num_episodes = 10000 #i have incresed this after i got accuracy 51%\n", "\n", "\n", "def choose_action(state_index):\n", " if np.random.uniform(0, 1) < epsilon:\n", - " return np.random.choice(actions) \n", + " return np.random.choice(actions)\n", " else:\n", - " return np.argmax(q_table[state_index, :]) " + " return np.argmax(q_table[state_index, :])" ] }, { "cell_type": "code", - "execution_count": 209, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "73jWTg9xS6ON", + "outputId": "30ce35b8-8600-4881-eb85-8ffda6f5435b" + }, "outputs": [ { "name": "stdout", @@ -3554,20 +3639,20 @@ "source": [ "# Training the agent\n", "for episode in range(num_episodes):\n", - " \n", + "\n", " state_index = np.random.randint(0, len(states))\n", " done = False\n", - " \n", + "\n", " while not done:\n", " action = choose_action(state_index)\n", - " \n", + "\n", " next_state_index = (state_index + 1) % len(states)\n", " reward = dataset.iloc[next_state_index]['recommended']\n", - " \n", + "\n", " # Q-learning update\n", " q_table[state_index, action] = q_table[state_index, action] + alpha * (\n", " reward + gamma * np.max(q_table[next_state_index, :]) - q_table[state_index, action])\n", - " \n", + "\n", " state_index = next_state_index\n", " done = state_index == 0\n", "\n", @@ -3576,8 +3661,11 @@ }, { "cell_type": "code", - "execution_count": 210, - "metadata": {}, + "execution_count": null, + "metadata": { + "id": "IKnPseuKS6ON", + "outputId": "2c457e79-7ecc-4673-eaa1-9213e7653b77" + }, "outputs": [ { "name": "stdout", @@ -3591,11 +3679,11 @@ "def evaluate_policy(q_table, states, actions):\n", " correct_predictions = 0\n", " total_predictions = len(states)\n", - " \n", + "\n", " for state_index in range(total_predictions):\n", " action = np.argmax(q_table[state_index, :])\n", " correct_predictions += int(action == dataset.iloc[state_index]['recommended'])\n", - " \n", + "\n", " accuracy = correct_predictions / total_predictions\n", " return accuracy\n", "\n", @@ -3603,131 +3691,104 @@ "print(f\"Policy accuracy: {accuracy:.2f}\")" ] }, + { + "cell_type": "markdown", + "metadata": { + "id": "WlOhu_l4TJ9B" + }, + "source": [ + "# ILP For Airline Data" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "#!pip install PyILP\n", + "#!pip install texttable" + ] }, { "cell_type": "code", - "execution_count": 219, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Facts have been successfully generated and saved to 'facts.pl'.\n" - ] - } - ], + "execution_count": 31, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "8H74hLUPTP3B", + "outputId": "4f5fd7ea-dbd5-43d9-f9a6-4d58f295077e" + }, + "outputs": [], "source": [ - "# Load the dataset\n", - "df2 = pd.read_csv('cleanedairline_pred_data.csv')\n", - "df2.head()\n", - "\n", - "\n", - "# Fill numerical NaNs with the mean\n", - "numerical_features = ['overall', 'seat_comfort', 'cabin_service', 'food_bev', 'entertainment', 'ground_service', 'value_for_money']\n", - "df2[numerical_features] = df2[numerical_features].fillna(df2[numerical_features].mean())\n", - "\n", - "# Convert `recommended` to binary\n", - "df2['recommended'] = df2['recommended'].apply(lambda x: 1 if x == 'yes' else 0)\n", - "\n", - "# Define mappings for traveller type and cabin based on the one-hot encoded columns\n", - "traveller_type_columns = ['Couple Leisure', 'Family Leisure', 'Solo Leisure']\n", - "cabin_columns = ['Economy Class', 'First Class', 'Premium Economy']\n", - "\n", - "def get_traveller_type(row):\n", - " for col in traveller_type_columns:\n", - " if row[col]:\n", - " return col.replace(' ', '_')\n", - " return 'Unknown'\n", - "\n", - "def get_cabin_type(row):\n", - " for col in cabin_columns:\n", - " if row[col]:\n", - " return col.replace(' ', '_')\n", - " return 'Unknown'\n", + "import numpy as np\n", + "import pandas as pd\n", + "# Load the clean airline dataset\n", + "cleaned_airline_data = pd.read_csv('cleanedairline_pred_data.csv')\n", "\n", - "# Save facts to a Prolog file\n", - "with open('facts.pl', 'w') as f:\n", - " for _, row in df2.iterrows():\n", - " traveller_type = get_traveller_type(row)\n", - " cabin = get_cabin_type(row)\n", - " fact = f\"recommended({traveller_type}, {cabin}, {int(row['seat_comfort'])}, {int(row['cabin_service'])}, {int(row['food_bev'])}, {int(row['entertainment'])}, {int(row['ground_service'])}, {int(row['value_for_money'])}).\\n\"\n", - " f.write(fact)\n", - "print(\"Facts have been successfully generated and saved to 'facts.pl'.\")" + "facts = open(\"facts.pl\",'w')\n", + "positives_file = open(\"positives_file.pl\",'w')\n", + "negatives_file = open(\"negatives_file.pl\",'w')\n", + "for i,data in cleaned_airline_data.iterrows():\n", + " facts.write('ground_service('+str(i)+\",\"+str(data[\"ground_service\"])+\").\\n\")\n", + " facts.write('value_for_money('+str(i)+\",\"+str(data[\"value_for_money\"])+\").\\n\")\n", + " if data[\"recommended\"]==0:\n", + " negatives_file.write(\"recommended(\"+str(i)+\").\\n\")\n", + " else:\n", + " positives_file.write(\"recommended(\"+str(i)+\").\\n\")\n", + " if i>200 :break\n", + "facts.close()\n", + "positives_file.close()\n", + "negatives_file.close()" ] }, { "cell_type": "code", - "execution_count": 220, - "metadata": {}, + "execution_count": 33, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 351 + }, + "id": "snsE7NpOTQG7", + "outputId": "0113b939-0485-42a2-ce54-5f38f1f35055" + }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Number of positive examples: 0\n", - "Number of negative examples: 29731\n", - "Positive and negative examples have been successfully generated and saved to 'positiveexamples.f' and 'negativeexamples.n'.\n" + "['recommended(0).recommended(A) :- value_for_money(A,5.0).recommended(8).recommended(15).recommended(16).recommended(17).recommended(18).recommended(32).recommended(A) :- ground_service(A,5.0), value_for_money(A,4.0).recommended(36).recommended(53).recommended(77).recommended(80).recommended(82).recommended(83).recommended(84).recommended(91).recommended(94).recommended(95).recommended(117).recommended(121).recommended(138).recommended(141).']\n", + "+----------+ Testing +----------+\n", + "+---------------------+------------------+------------------+\n", + "| n = 61 | Positive(Actual) | Negative(Actual) |\n", + "+=====================+==================+==================+\n", + "| Positive(Predicted) | 21 | 1 |\n", + "+---------------------+------------------+------------------+\n", + "| Negative(Predicted) | 0 | 39 |\n", + "+---------------------+------------------+------------------+\n", + "+-------------+-------+\n", + "| Metric | # |\n", + "+=============+=======+\n", + "| Accuracy | 0.984 |\n", + "+-------------+-------+\n", + "| Precision | 0.955 |\n", + "+-------------+-------+\n", + "| Sensitivity | 1 |\n", + "+-------------+-------+\n", + "| Specificity | 0.975 |\n", + "+-------------+-------+\n", + "| F1 Score | 0.977 |\n", + "+-------------+-------+\n" ] } ], "source": [ - "traveller_type_columns = ['Couple Leisure', 'Family Leisure', 'Solo Leisure']\n", - "cabin_columns = ['Economy Class', 'First Class', 'Premium Economy']\n", "\n", - "def get_traveller_type(row):\n", - " for col in traveller_type_columns:\n", - " if row[col]:\n", - " return col.replace(' ', '_').lower()\n", - " return 'unknown'\n", - "\n", - "def get_cabin_type(row):\n", - " for col in cabin_columns:\n", - " if row[col]:\n", - " return col.replace(' ', '_').lower()\n", - " return 'unknown'\n", - "\n", - "\n", - "positive_examples = []\n", - "negative_examples = []\n", - "\n", - "for _, row in df2.iterrows():\n", - " traveller_type = get_traveller_type(row)\n", - " cabin = get_cabin_type(row)\n", - " fact = f\"recommended({traveller_type}, {cabin}, {int(row['seat_comfort'])}, {int(row['cabin_service'])}, {int(row['food_bev'])}, {int(row['entertainment'])}, {int(row['ground_service'])}, {int(row['value_for_money'])}).\"\n", - " if row['recommended'] == 1:\n", - " positive_examples.append(fact)\n", - " else:\n", - " negative_examples.append(fact)\n", - "\n", - "print(\"Number of positive examples:\", len(positive_examples))\n", - "print(\"Number of negative examples:\", len(negative_examples))\n", - "\n", - "# Save positive examples to file\n", - "with open('positiveexamples.f', 'w') as f:\n", - " for example in positive_examples:\n", - " f.write(example + '\\n')\n", - "\n", - "# Save negative examples to file\n", - "with open('negativeexamples.n', 'w') as f:\n", - " for example in negative_examples:\n", - " f.write(example + '\\n')\n", - "\n", - "print(\"Positive and negative examples have been successfully generated and saved to 'positiveexamples.f' and 'negativeexamples.n'.\")" + "from PyILP.PyILP import *\n", + "model_2=aleph_learn(file=\"facts.pl\", positive_example=\"positives_file.pl\", negative_example=\"negatives_file.pl\", test_size=0.3)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -3753,5 +3814,5 @@ } }, "nbformat": 4, - "nbformat_minor": 4 + "nbformat_minor": 1 }