Skip to content

Commit

Permalink
Refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
LastBencher-98 committed Dec 11, 2019
1 parent c92d4a8 commit 126632d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 1_find_s/1_find_s.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"nbformat":4,"nbformat_minor":0,"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.5"},"colab":{"name":"1_find_s.ipynb","provenance":[{"file_id":"https://github.com/ravish0007/ml/blob/master/1_find_s/1_find_s.ipynb","timestamp":1576086736463}],"collapsed_sections":[]}},"cells":[{"cell_type":"markdown","metadata":{"id":"t4mR-563FcgK","colab_type":"text"},"source":["# 1 : Implement and demonstrate the FIND-S algorithm"]},{"cell_type":"code","metadata":{"id":"kBPC4-R9FcgN","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":204},"outputId":"8aab9735-57a5-4c0b-84e6-7d8a7224c54e","executionInfo":{"status":"ok","timestamp":1576086765491,"user_tz":-330,"elapsed":4402,"user":{"displayName":"Vishal Nayak","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mCTt-Ft0O7FZnNLCmaQV0OjoOQY-UE6BjazKy6QeTc=s64","userId":"05008619478332300738"}}},"source":["import random\n","import csv\n","\n","!wget 'https://raw.githubusercontent.com/LastBencher-98/ml/master/1_find_s/data.csv'"],"execution_count":1,"outputs":[{"output_type":"stream","text":["--2019-12-11 17:52:43-- https://raw.githubusercontent.com/LastBencher-98/ml/master/1_find_s/data.csv\n","Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.0.133, 151.101.64.133, 151.101.128.133, ...\n","Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.0.133|:443... connected.\n","HTTP request sent, awaiting response... 200 OK\n","Length: 157 [text/plain]\n","Saving to: ‘data.csv’\n","\n","\rdata.csv 0%[ ] 0 --.-KB/s \rdata.csv 100%[===================>] 157 --.-KB/s in 0s \n","\n","2019-12-11 17:52:43 (38.6 MB/s) - ‘data.csv’ saved [157/157]\n","\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"re26NY2nFcgR","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"RGlAxQ1LFcgR","colab_type":"code","colab":{}},"source":["attributes = [ \n"," ['Sunny','Rainy' ],\n"," ['Warm','Cold' ],\n"," ['Normal','High' ],\n"," ['Strong','Weak' ],\n"," ['Warm','Cool' ],\n"," ['Same','Change' ]\n"," ]"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"Jjj7gyV9FcgU","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"mX8HyWolFcgU","colab_type":"code","colab":{}},"source":["\n","data_list = []\n","\n","with open('data.csv', 'r') as csvFile:\n"," reader = csv.reader(csvFile)\n"," for row in reader:\n"," data_list.append(row)\n"," "],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"qV5py3aNFcgX","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"w39NXB7SFcgX","colab_type":"code","outputId":"fb3eeb50-6c44-4bef-b017-28bfc561a030","colab":{"base_uri":"https://localhost:8080/","height":85},"executionInfo":{"status":"ok","timestamp":1576086765495,"user_tz":-330,"elapsed":4342,"user":{"displayName":"Vishal Nayak","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mCTt-Ft0O7FZnNLCmaQV0OjoOQY-UE6BjazKy6QeTc=s64","userId":"05008619478332300738"}}},"source":["num_attributes = len(attributes)\n","hypothesis = ['0'] * num_attributes\n","\n","print(\"The initial value of hypothesis:\", end='\\n'*3)\n","print(hypothesis)"],"execution_count":4,"outputs":[{"output_type":"stream","text":["The initial value of hypothesis:\n","\n","\n","['0', '0', '0', '0', '0', '0']\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"eC85IumhFcga","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"EGPVOu8yFcgb","colab_type":"code","colab":{}},"source":["# Comparing with First Training Example ( Assigning )\n","\n","*first_sample, output = data_list[0] \n","hypothesis = first_sample[:] # Deep copy\n"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"7Jhj_aEaFcge","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"ekVnwB4-Fcgf","colab_type":"code","outputId":"77048ad7-4bfe-4ba4-8d42-1d9d225fbeec","colab":{"base_uri":"https://localhost:8080/","height":136},"executionInfo":{"status":"ok","timestamp":1576086765498,"user_tz":-330,"elapsed":4323,"user":{"displayName":"Vishal Nayak","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mCTt-Ft0O7FZnNLCmaQV0OjoOQY-UE6BjazKy6QeTc=s64","userId":"05008619478332300738"}}},"source":["\n","# Comparing with Remaining Training Examples of Given Data Set\n","\n","print(\"Find S: Finding a Maximally Specific Hypothesis\", end='\\n'*3)\n","\n","outer_index = 1\n","\n","for *data, output in data_list: \n"," \n"," if output == 'Yes':\n"," for index, attribute in enumerate(data): \n"," if attribute != hypothesis[index]:\n"," hypothesis[index] = '?'\n"," \n"," \n"," \n"," print(\"For Training Example No : {0} the hypothesis is {1} \".format( outer_index, hypothesis) )\n"," outer_index += 1 \n"],"execution_count":6,"outputs":[{"output_type":"stream","text":["Find S: Finding a Maximally Specific Hypothesis\n","\n","\n","For Training Example No : 1 the hypothesis is ['Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same'] \n","For Training Example No : 2 the hypothesis is ['Sunny', 'Warm', '?', 'Strong', 'Warm', 'Same'] \n","For Training Example No : 3 the hypothesis is ['Sunny', 'Warm', '?', 'Strong', 'Warm', 'Same'] \n","For Training Example No : 4 the hypothesis is ['Sunny', 'Warm', '?', 'Strong', '?', '?'] \n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"l0dQo2YEFcgh","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"uliiD9nmFcgh","colab_type":"code","outputId":"a69b0be4-8c49-471e-e885-30520269bc80","colab":{"base_uri":"https://localhost:8080/","height":68},"executionInfo":{"status":"ok","timestamp":1576086765499,"user_tz":-330,"elapsed":4297,"user":{"displayName":"Vishal Nayak","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mCTt-Ft0O7FZnNLCmaQV0OjoOQY-UE6BjazKy6QeTc=s64","userId":"05008619478332300738"}}},"source":["print(\" The Maximally Specific Hypothesis for a given Training Examples:\", end='\\n'*2)\n","print(hypothesis)"],"execution_count":7,"outputs":[{"output_type":"stream","text":[" The Maximally Specific Hypothesis for a given Training Examples:\n","\n","['Sunny', 'Warm', '?', 'Strong', '?', '?']\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"6fmZsqCJFcgk","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"57Hzm0sWFcgl","colab_type":"code","outputId":"9ae57177-90ad-491a-e7ce-690e2da3d648","colab":{"base_uri":"https://localhost:8080/","height":102},"executionInfo":{"status":"ok","timestamp":1576086765499,"user_tz":-330,"elapsed":4279,"user":{"displayName":"Vishal Nayak","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mCTt-Ft0O7FZnNLCmaQV0OjoOQY-UE6BjazKy6QeTc=s64","userId":"05008619478332300738"}}},"source":["# PS: Dataset for clarity\n","print(open('data.csv').read())"],"execution_count":8,"outputs":[{"output_type":"stream","text":["Sunny,Warm,Normal,Strong,Warm,Same,Yes\n","Sunny,Warm,High,Strong,Warm,Same,Yes\n","Rainy,Cold,High,Strong,Warm,Change,No\n","Sunny,Warm,High,Strong,Cool,Change,Yes\n","\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"8ABA3uj-Fcgn","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]}]}
{"nbformat":4,"nbformat_minor":0,"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.5"},"colab":{"name":"1_find_s.ipynb","provenance":[{"file_id":"https://github.com/ravish0007/ml/blob/master/1_find_s/1_find_s.ipynb","timestamp":1576086736463}],"collapsed_sections":[]}},"cells":[{"cell_type":"markdown","metadata":{"id":"t4mR-563FcgK","colab_type":"text"},"source":["# 1 : Implement and demonstrate the FIND-S algorithm"]},{"cell_type":"code","metadata":{"id":"kBPC4-R9FcgN","colab_type":"code","colab":{}},"source":["import random\n","import csv\n","\n","!wget 'https://raw.githubusercontent.com/LastBencher-98/ml/master/1_find_s/data.csv'"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"re26NY2nFcgR","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"RGlAxQ1LFcgR","colab_type":"code","colab":{}},"source":["attributes = [ \n"," ['Sunny','Rainy' ],\n"," ['Warm','Cold' ],\n"," ['Normal','High' ],\n"," ['Strong','Weak' ],\n"," ['Warm','Cool' ],\n"," ['Same','Change' ]\n"," ]"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"Jjj7gyV9FcgU","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"mX8HyWolFcgU","colab_type":"code","colab":{}},"source":["\n","data_list = []\n","\n","with open('data.csv', 'r') as csvFile:\n"," reader = csv.reader(csvFile)\n"," for row in reader:\n"," data_list.append(row)\n"," "],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"qV5py3aNFcgX","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"w39NXB7SFcgX","colab_type":"code","outputId":"fb3eeb50-6c44-4bef-b017-28bfc561a030","colab":{"base_uri":"https://localhost:8080/","height":85},"executionInfo":{"status":"ok","timestamp":1576086765495,"user_tz":-330,"elapsed":4342,"user":{"displayName":"Vishal Nayak","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mCTt-Ft0O7FZnNLCmaQV0OjoOQY-UE6BjazKy6QeTc=s64","userId":"05008619478332300738"}}},"source":["num_attributes = len(attributes)\n","hypothesis = ['0'] * num_attributes\n","\n","print(\"The initial value of hypothesis:\", end='\\n'*3)\n","print(hypothesis)"],"execution_count":4,"outputs":[{"output_type":"stream","text":["The initial value of hypothesis:\n","\n","\n","['0', '0', '0', '0', '0', '0']\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"eC85IumhFcga","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"EGPVOu8yFcgb","colab_type":"code","colab":{}},"source":["# Comparing with First Training Example ( Assigning )\n","\n","*first_sample, output = data_list[0] \n","hypothesis = first_sample[:] # Deep copy\n"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"7Jhj_aEaFcge","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"ekVnwB4-Fcgf","colab_type":"code","outputId":"77048ad7-4bfe-4ba4-8d42-1d9d225fbeec","colab":{"base_uri":"https://localhost:8080/","height":136},"executionInfo":{"status":"ok","timestamp":1576086765498,"user_tz":-330,"elapsed":4323,"user":{"displayName":"Vishal Nayak","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mCTt-Ft0O7FZnNLCmaQV0OjoOQY-UE6BjazKy6QeTc=s64","userId":"05008619478332300738"}}},"source":["\n","# Comparing with Remaining Training Examples of Given Data Set\n","\n","print(\"Find S: Finding a Maximally Specific Hypothesis\", end='\\n'*3)\n","\n","outer_index = 1\n","\n","for *data, output in data_list: \n"," \n"," if output == 'Yes':\n"," for index, attribute in enumerate(data): \n"," if attribute != hypothesis[index]:\n"," hypothesis[index] = '?'\n"," \n"," \n"," \n"," print(\"For Training Example No : {0} the hypothesis is {1} \".format( outer_index, hypothesis) )\n"," outer_index += 1 \n"],"execution_count":6,"outputs":[{"output_type":"stream","text":["Find S: Finding a Maximally Specific Hypothesis\n","\n","\n","For Training Example No : 1 the hypothesis is ['Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same'] \n","For Training Example No : 2 the hypothesis is ['Sunny', 'Warm', '?', 'Strong', 'Warm', 'Same'] \n","For Training Example No : 3 the hypothesis is ['Sunny', 'Warm', '?', 'Strong', 'Warm', 'Same'] \n","For Training Example No : 4 the hypothesis is ['Sunny', 'Warm', '?', 'Strong', '?', '?'] \n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"l0dQo2YEFcgh","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"uliiD9nmFcgh","colab_type":"code","outputId":"a69b0be4-8c49-471e-e885-30520269bc80","colab":{"base_uri":"https://localhost:8080/","height":68},"executionInfo":{"status":"ok","timestamp":1576086765499,"user_tz":-330,"elapsed":4297,"user":{"displayName":"Vishal Nayak","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mCTt-Ft0O7FZnNLCmaQV0OjoOQY-UE6BjazKy6QeTc=s64","userId":"05008619478332300738"}}},"source":["print(\" The Maximally Specific Hypothesis for a given Training Examples:\", end='\\n'*2)\n","print(hypothesis)"],"execution_count":7,"outputs":[{"output_type":"stream","text":[" The Maximally Specific Hypothesis for a given Training Examples:\n","\n","['Sunny', 'Warm', '?', 'Strong', '?', '?']\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"6fmZsqCJFcgk","colab_type":"text"},"source":[" "]},{"cell_type":"code","metadata":{"id":"57Hzm0sWFcgl","colab_type":"code","outputId":"9ae57177-90ad-491a-e7ce-690e2da3d648","colab":{"base_uri":"https://localhost:8080/","height":102},"executionInfo":{"status":"ok","timestamp":1576086765499,"user_tz":-330,"elapsed":4279,"user":{"displayName":"Vishal Nayak","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mCTt-Ft0O7FZnNLCmaQV0OjoOQY-UE6BjazKy6QeTc=s64","userId":"05008619478332300738"}}},"source":["# PS: Dataset for clarity\n","print(open('data.csv').read())"],"execution_count":8,"outputs":[{"output_type":"stream","text":["Sunny,Warm,Normal,Strong,Warm,Same,Yes\n","Sunny,Warm,High,Strong,Warm,Same,Yes\n","Rainy,Cold,High,Strong,Warm,Change,No\n","Sunny,Warm,High,Strong,Cool,Change,Yes\n","\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"8ABA3uj-Fcgn","colab_type":"code","colab":{}},"source":[""],"execution_count":0,"outputs":[]}]}
Loading

0 comments on commit 126632d

Please sign in to comment.