├── README.md ├── Exp 1 - Hypothesis Testing 1 ├── Readme.md ├── goesexp1.csv └── MLITD_EXP1.ipynb └── Exp 2 - Cadidate Elimination ├── Readme.md ├── goesexp1.csv └── MLITD_EXP2.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # MLITD -------------------------------------------------------------------------------- /Exp 1 - Hypothesis Testing 1/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Exp 2 - Cadidate Elimination/Readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Exp 1 - Hypothesis Testing 1/goesexp1.csv: -------------------------------------------------------------------------------- 1 | Time,Weather,Temperature,Company,Humidity,Wind,Goes 2 | Morning,Sunny,Warm,Yes,Mild,Strong,Yes 3 | Evening,Rainy,Cold,No,Mild,Normal,No 4 | Morning,Sunny,Moderate,Yes,Normal,Normal,Yes 5 | Evening,Sunny,Cold,Yes,High,Strong,Yes 6 | -------------------------------------------------------------------------------- /Exp 2 - Cadidate Elimination/goesexp1.csv: -------------------------------------------------------------------------------- 1 | Time,Weather,Temperature,Company,Humidity,Wind,Goes 2 | Morning,Sunny,Warm,Yes,Mild,Strong,Yes 3 | Evening,Rainy,Cold,No,Mild,Normal,No 4 | Morning,Sunny,Moderate,Yes,Normal,Normal,Yes 5 | Evening,Sunny,Cold,Yes,High,Strong,Yes 6 | -------------------------------------------------------------------------------- /Exp 1 - Hypothesis Testing 1/MLITD_EXP1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": { 21 | "colab": { 22 | "base_uri": "https://localhost:8080/" 23 | }, 24 | "id": "5JZXaK5Y5uMT", 25 | "outputId": "ddcd9c71-fdbd-46bb-c869-3b48fb13944c" 26 | }, 27 | "outputs": [ 28 | { 29 | "output_type": "stream", 30 | "name": "stdout", 31 | "text": [ 32 | "---------DataSet----------\n", 33 | " Time Weather Temperature Company Humidity Wind Goes\n", 34 | "0 Morning Sunny Warm Yes Mild Strong Yes\n", 35 | "1 Evening Rainy Cold No Mild Normal No\n", 36 | "2 Morning Sunny Moderate Yes Normal Normal Yes\n", 37 | "3 Evening Sunny Cold Yes High Strong Yes\n", 38 | "\n", 39 | "\n", 40 | "---------Attributes----------\n", 41 | "The attributes are: [['Morning' 'Sunny' 'Warm' 'Yes' 'Mild' 'Strong']\n", 42 | " ['Evening' 'Rainy' 'Cold' 'No' 'Mild' 'Normal']\n", 43 | " ['Morning' 'Sunny' 'Moderate' 'Yes' 'Normal' 'Normal']\n", 44 | " ['Evening' 'Sunny' 'Cold' 'Yes' 'High' 'Strong']]\n", 45 | "\n", 46 | "\n", 47 | "---------Targets----------\n", 48 | "The target is: ['Yes' 'No' 'Yes' 'Yes']\n", 49 | "\n", 50 | "\n", 51 | "---------Hypothesis----------\n", 52 | "The final hypothesis is: ['?' 'Sunny' '?' 'Yes' '?' '?']\n" 53 | ] 54 | } 55 | ], 56 | "source": [ 57 | "import pandas as pd\n", 58 | "import numpy as np\n", 59 | "\n", 60 | "df = pd.read_csv(\"goesexp1.csv\")\n", 61 | "print(\"---------DataSet----------\")\n", 62 | "print(df)\n", 63 | "print(\"\\n\")\n", 64 | "d = np.array(df)[:,:-1]\n", 65 | "print(\"---------Attributes----------\")\n", 66 | "print(\"The attributes are: \",d)\n", 67 | "print(\"\\n\")\n", 68 | "target = np.array(df)[:,-1]\n", 69 | "print(\"---------Targets----------\")\n", 70 | "print(\"The target is: \",target)\n", 71 | "print(\"\\n\")\n", 72 | "\n", 73 | "def find_s(concepts, targets):\n", 74 | " specific_hypothesis = None\n", 75 | " for i, target in enumerate(targets):\n", 76 | " if target == \"Yes\":\n", 77 | " specific_hypothesis = concepts[i].copy()\n", 78 | " break\n", 79 | "\n", 80 | " for i, concept in enumerate(concepts):\n", 81 | " if targets[i] == \"Yes\":\n", 82 | " for x in range(len(specific_hypothesis)):\n", 83 | " if concept[x] != specific_hypothesis[x]:\n", 84 | " specific_hypothesis[x] = '?'\n", 85 | " else:\n", 86 | " pass\n", 87 | "\n", 88 | " return specific_hypothesis\n", 89 | "print(\"---------Hypothesis----------\")\n", 90 | "print(\"The final hypothesis is:\",find_s(d,target))\n" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "source": [], 96 | "metadata": { 97 | "id": "fKTAmyjd6rKw" 98 | }, 99 | "execution_count": null, 100 | "outputs": [] 101 | } 102 | ] 103 | } -------------------------------------------------------------------------------- /Exp 2 - Cadidate Elimination/MLITD_EXP2.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "nbformat": 4, 3 | "nbformat_minor": 0, 4 | "metadata": { 5 | "colab": { 6 | "provenance": [] 7 | }, 8 | "kernelspec": { 9 | "name": "python3", 10 | "display_name": "Python 3" 11 | }, 12 | "language_info": { 13 | "name": "python" 14 | } 15 | }, 16 | "cells": [ 17 | { 18 | "cell_type": "code", 19 | "execution_count": null, 20 | "metadata": { 21 | "colab": { 22 | "base_uri": "https://localhost:8080/" 23 | }, 24 | "id": "HlcTsNcWZxU-", 25 | "outputId": "694641cf-b91c-47e1-bb7d-bcc9ccb14a3a" 26 | }, 27 | "outputs": [ 28 | { 29 | "output_type": "stream", 30 | "name": "stdout", 31 | "text": [ 32 | "Instances are: [['sunny' 'warm' 'normal' 'strong' 'warm' 'same']\n", 33 | " ['sunny' 'warm' 'high' 'strong' 'warm' 'same']\n", 34 | " ['rainy' 'cold' 'high' 'strong' 'warm' 'change']\n", 35 | " ['sunny' 'warm' 'high' 'strong' 'cool' 'change']]\n", 36 | "\n", 37 | "\n", 38 | "Target Values are: ['yes' 'yes' 'no' 'yes']\n", 39 | "\n", 40 | "Initialization of specific_h and genearal_h\n", 41 | "Specific Boundary: ['sunny' 'warm' 'normal' 'strong' 'warm' 'same']\n", 42 | "\n", 43 | "Generic Boundary: [['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?']]\n", 44 | "\n", 45 | "Instance 1 is ['sunny' 'warm' 'normal' 'strong' 'warm' 'same']\n", 46 | "Instance is Positive \n", 47 | "Specific Bundary after 1 Instance is ['sunny' 'warm' 'normal' 'strong' 'warm' 'same']\n", 48 | "Generic Boundary after 1 Instance is [['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?']]\n", 49 | "\n", 50 | "\n", 51 | "\n", 52 | "Instance 2 is ['sunny' 'warm' 'high' 'strong' 'warm' 'same']\n", 53 | "Instance is Positive \n", 54 | "Specific Bundary after 2 Instance is ['sunny' 'warm' '?' 'strong' 'warm' 'same']\n", 55 | "Generic Boundary after 2 Instance is [['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?']]\n", 56 | "\n", 57 | "\n", 58 | "\n", 59 | "Instance 3 is ['rainy' 'cold' 'high' 'strong' 'warm' 'change']\n", 60 | "Instance is Negative \n", 61 | "Specific Bundary after 3 Instance is ['sunny' 'warm' '?' 'strong' 'warm' 'same']\n", 62 | "Generic Boundary after 3 Instance is [['sunny', '?', '?', '?', '?', '?'], ['?', 'warm', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', 'same']]\n", 63 | "\n", 64 | "\n", 65 | "\n", 66 | "Instance 4 is ['sunny' 'warm' 'high' 'strong' 'cool' 'change']\n", 67 | "Instance is Positive \n", 68 | "Specific Bundary after 4 Instance is ['sunny' 'warm' '?' 'strong' '?' '?']\n", 69 | "Generic Boundary after 4 Instance is [['sunny', '?', '?', '?', '?', '?'], ['?', 'warm', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?'], ['?', '?', '?', '?', '?', '?']]\n", 70 | "\n", 71 | "\n", 72 | "Final Specific_h: \n", 73 | "['sunny' 'warm' '?' 'strong' '?' '?']\n", 74 | "Final General_h: \n", 75 | "[['sunny', '?', '?', '?', '?', '?'], ['?', 'warm', '?', '?', '?', '?']]\n" 76 | ] 77 | } 78 | ], 79 | "source": [ 80 | "import numpy as np\n", 81 | "import pandas as pd\n", 82 | "\n", 83 | "data = pd.read_csv('data.csv')\n", 84 | "concepts = np.array(data.iloc[:,0:-1])\n", 85 | "print(\"Instances are: \",concepts)\n", 86 | "target = np.array(data.iloc[:,-1])\n", 87 | "print(\"\\n\")\n", 88 | "print(\"Target Values are: \",target)\n", 89 | "\n", 90 | "def gen(concepts, target):\n", 91 | " specific_h = concepts[0].copy()\n", 92 | " print(\"\\nInitialization of specific_h and genearal_h\")\n", 93 | " print(\"Specific Boundary: \", specific_h)\n", 94 | " general_h = [[\"?\" for i in range(len(specific_h))] for i in range(len(specific_h))]\n", 95 | " print(\"\\nGeneric Boundary: \",general_h)\n", 96 | "\n", 97 | " for i, h in enumerate(concepts):\n", 98 | " print(\"\\nInstance\", i+1 , \"is \", h)\n", 99 | " if target[i] == \"yes\":\n", 100 | " print(\"Instance is Positive \")\n", 101 | " for x in range(len(specific_h)):\n", 102 | " if h[x]!= specific_h[x]:\n", 103 | " specific_h[x] ='?'\n", 104 | " general_h[x][x] ='?'\n", 105 | "\n", 106 | " if target[i] == \"no\":\n", 107 | " print(\"Instance is Negative \")\n", 108 | " for x in range(len(specific_h)):\n", 109 | " if h[x]!= specific_h[x]:\n", 110 | " general_h[x][x] = specific_h[x]\n", 111 | " else:\n", 112 | " general_h[x][x] = '?'\n", 113 | "\n", 114 | " print(\"Specific Bundary after \", i+1, \"Instance is \", specific_h)\n", 115 | " print(\"Generic Boundary after \", i+1, \"Instance is \", general_h)\n", 116 | " print(\"\\n\")\n", 117 | "\n", 118 | " indices = [i for i, val in enumerate(general_h) if val == ['?', '?', '?', '?', '?', '?']]\n", 119 | " for i in indices:\n", 120 | " general_h.remove(['?', '?', '?', '?', '?', '?'])\n", 121 | " return specific_h, general_h\n", 122 | "\n", 123 | "s_final, g_final = gen(concepts, target)\n", 124 | "\n", 125 | "print(\"Final Specific_h: \", s_final, sep=\"\\n\")\n", 126 | "print(\"Final General_h: \", g_final, sep=\"\\n\")" 127 | ] 128 | } 129 | ] 130 | } --------------------------------------------------------------------------------