From 82e5e1b078ec9f7398328b48c6975fde0102c84d Mon Sep 17 00:00:00 2001 From: ArisGoulas Date: Wed, 19 Apr 2023 21:23:53 +0100 Subject: [PATCH 1/2] lab done --- your-code/challenge-1.ipynb | 168 ++++++++++++++++++++++----- your-code/challenge-2.ipynb | 222 ++++++++++++++++++++++++++++++++---- 2 files changed, 339 insertions(+), 51 deletions(-) diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index c574eba..e09fe55 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -33,12 +33,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Durante un tiempo no estuvo segura de si su marido era su marido.\n" + ] + } + ], "source": [ "str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", - "# Your code here:\n" + "# Your code here:\n", + "comb_list = \" \".join(str_list) + \".\"\n", + "print(comb_list)" ] }, { @@ -50,12 +60,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Grocery list: bananas, bread, brownie mix, broccoli.\n" + ] + } + ], "source": [ "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", - "# Your code here:\n" + "# Your code here:\n", + "food_lower = [food.lower() for food in food_list]\n", + "\n", + "grocery_list = \"Grocery list: \" + \", \".join([food for food in food_lower if food.startswith(\"b\")]) + \".\"\n", + "print(grocery_list)" ] }, { @@ -69,9 +91,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The area of the circle with radius: 4.5 is: 63.61725123519331.\n" + ] + } + ], "source": [ "import math\n", "\n", @@ -90,7 +120,9 @@ " # Your code here:\n", " return pi * (x**2)\n", " \n", - "# Your output string here:\n" + "# Your output string here:\n", + "area = string1 + \" \" + str(radius) + \" \" + string2 + \" \" + str(area(radius)) + \".\"\n", + "print(area)" ] }, { @@ -106,9 +138,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice']\n", + "{'some': 2, 'say': 3, 'the': 1, 'world': 1, 'will': 1, 'end': 1, 'in': 2, 'fire': 2, 'ice': 2, 'from': 1, 'what': 1, 'i’ve': 1, 'tasted': 1, 'of': 2, 'desire': 1, 'i': 3, 'hold': 1, 'with': 1, 'those': 1, 'who': 1, 'favor': 1, 'but': 1, 'if': 1, 'it': 1, 'had': 1, 'to': 2, 'perish': 1, 'twice': 1, 'think': 1, 'know': 1, 'enough': 1, 'hate': 1, 'that': 1, 'for': 1, 'destruction': 1, 'is': 1, 'also': 1, 'great': 1, 'and': 1, 'would': 1, 'suffice': 1}\n" + ] + } + ], "source": [ "poem = \"\"\"Some say the world will end in fire,\n", "Some say in ice.\n", @@ -120,7 +161,21 @@ "Is also great\n", "And would suffice.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "clean_string = poem.replace('.', '').replace(',', '').replace('\\n', ' ').lower()\n", + "split_string = clean_string.split(' ')\n", + "\n", + "print(split_string)\n", + "\n", + "word_count = {}\n", + "\n", + "for word in split_string: \n", + " if word in word_count: \n", + " word_count[word] += 1\n", + " else: \n", + " word_count[word] = 1\n", + "\n", + "print(word_count)" ] }, { @@ -132,9 +187,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "98\n", + "78\n", + "['i', 'was', 'angry', 'with', 'my', 'friend', 'i', 'told', 'my', 'wrath', 'my', 'wrath', 'did', 'end', 'i', 'was', 'angry', 'with', 'my', 'foe', 'i', 'told', 'not', 'my', 'wrath', 'did', 'grow', 'i', 'waterd', 'fearsnight', '&', 'morning', 'with', 'my', 'tears', 'i', 'sunned', 'with', 'smilesand', 'with', 'soft', 'deceitful', 'wiles', 'grew', 'both', 'day', 'night', 'till', 'bore', 'apple', 'bright', 'my', 'foe', 'beheld', 'shineand', 'he', 'knew', 'that', 'was', 'mine', 'into', 'my', 'garden', 'stole', 'when', 'night', 'had', 'veild', 'pole', 'morning', 'glad', 'i', 'see', 'my', 'foe', 'outstretched', 'beneath', 'tree']\n" + ] + } + ], "source": [ "blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n", "\n", @@ -158,7 +223,17 @@ "In the morning glad I see; \n", "My foe outstretched beneath the tree.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "clean_string = poem.replace('.', ' ').replace(':', '').replace(';', '').replace(',', '').replace('\\n', '').lower()\n", + "split_string = clean_string.split(' ')\n", + "\n", + "remove_empty = [word for word in split_string if word]\n", + "\n", + "words_found = [word for word in remove_empty if word not in blacklist]\n", + "\n", + "print(len(remove_empty))\n", + "print(len(words_found))\n", + "print(words_found)" ] }, { @@ -172,16 +247,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['T', 'P']" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import re\n", "\n", "poem = \"\"\"The apparition of these faces in the crowd;\n", "Petals on a wet, black bough.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "re.findall(\"[A-Z]\", poem)" ] }, { @@ -193,13 +280,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['123abc', 'abc123', 'JohnSmith1', 'ABBY4']\n" + ] + } + ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "contains_number = [x for x in data if re.search(\"[0-9]+\", x)]\n", + "print(contains_number)" ] }, { @@ -215,18 +312,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['123abc', 'abc123', 'JohnSmith1']\n" + ] + } + ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", - "# Your code here:\n" + "# Your code here:\n", + "filtered_list = [x for x in data if (re.search(\"[0-9]+\", x) and re.search(\"[a-z]+\", x))]\n", + "print(filtered_list)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -240,7 +354,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.10.9" } }, "nbformat": 4, diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 6873bd2..13561bf 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -72,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ @@ -88,11 +88,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" + ] + } + ], "source": [ - "# Write your code here\n" + "# Write your code here\n", + "import os\n", + "\n", + "corpus = []\n", + "\n", + "for file in docs:\n", + " with open(file, 'r') as f:\n", + " content = f.read()\n", + " corpus.append(content)\n", + " \n", + "print(corpus)" ] }, { @@ -104,10 +122,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 78, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" + ] + } + ], + "source": [ + "print(corpus)" + ] }, { "cell_type": "markdown", @@ -132,11 +160,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['ironhack is cool', 'i love ironhack', 'i am a student at ironhack']\n" + ] + } + ], "source": [ - "# Write your code here" + "# Write your code here\n", + "deletion_symbol = \".\"\n", + "\n", + "processed_corpus = []\n", + "\n", + "for doc in corpus:\n", + " processed_doc = doc.lower().replace(deletion_symbol, '')\n", + " processed_corpus.append(processed_doc)\n", + "\n", + "print(processed_corpus)" ] }, { @@ -148,10 +193,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 80, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "bag_of_words = []" + ] }, { "cell_type": "markdown", @@ -166,11 +213,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 81, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['ironhack', 'is', 'cool', 'i', 'love', 'am', 'a', 'student', 'at']\n" + ] + } + ], "source": [ - "# Write your code here\n" + "# Write your code here\n", + "for doc in processed_corpus:\n", + " words = doc.split()\n", + " for word in words:\n", + " if word not in bag_of_words:\n", + " bag_of_words.append(word)\n", + " \n", + "print(bag_of_words)" ] }, { @@ -186,7 +248,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, "outputs": [], "source": [] @@ -200,11 +262,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 84, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1, 1, 1, 0, 0, 0, 0, 0, 0], [1, 0, 0, 1, 1, 0, 0, 0, 0], [1, 0, 0, 1, 0, 1, 1, 1, 1]]\n" + ] + } + ], "source": [ - "# Write your code here\n" + "# Write your code here\n", + "term_freq = []\n", + "\n", + "for doc in processed_corpus:\n", + " words = doc.split()\n", + " freq_counts = []\n", + " for word in bag_of_words:\n", + " freq = words.count(word)\n", + " freq_counts.append(freq)\n", + " term_freq.append(freq_counts)\n", + "\n", + "print(term_freq)" ] }, { @@ -256,13 +337,69 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n", + "['ironhack is cool', 'i love ironhack', 'i am a student at ironhack']\n", + "['ironhack', 'cool', 'love', 'student']\n", + "[[1, 1, 0, 0], [1, 0, 1, 0], [1, 0, 0, 1]]\n" + ] + } + ], "source": [ "stop_words = ['all', 'six', 'less', 'being', 'indeed', 'over', 'move', 'anyway', 'fifty', 'four', 'not', 'own', 'through', 'yourselves', 'go', 'where', 'mill', 'only', 'find', 'before', 'one', 'whose', 'system', 'how', 'somewhere', 'with', 'thick', 'show', 'had', 'enough', 'should', 'to', 'must', 'whom', 'seeming', 'under', 'ours', 'has', 'might', 'thereafter', 'latterly', 'do', 'them', 'his', 'around', 'than', 'get', 'very', 'de', 'none', 'cannot', 'every', 'whether', 'they', 'front', 'during', 'thus', 'now', 'him', 'nor', 'name', 'several', 'hereafter', 'always', 'who', 'cry', 'whither', 'this', 'someone', 'either', 'each', 'become', 'thereupon', 'sometime', 'side', 'two', 'therein', 'twelve', 'because', 'often', 'ten', 'our', 'eg', 'some', 'back', 'up', 'namely', 'towards', 'are', 'further', 'beyond', 'ourselves', 'yet', 'out', 'even', 'will', 'what', 'still', 'for', 'bottom', 'mine', 'since', 'please', 'forty', 'per', 'its', 'everything', 'behind', 'un', 'above', 'between', 'it', 'neither', 'seemed', 'ever', 'across', 'she', 'somehow', 'be', 'we', 'full', 'never', 'sixty', 'however', 'here', 'otherwise', 'were', 'whereupon', 'nowhere', 'although', 'found', 'alone', 're', 'along', 'fifteen', 'by', 'both', 'about', 'last', 'would', 'anything', 'via', 'many', 'could', 'thence', 'put', 'against', 'keep', 'etc', 'amount', 'became', 'ltd', 'hence', 'onto', 'or', 'con', 'among', 'already', 'co', 'afterwards', 'formerly', 'within', 'seems', 'into', 'others', 'while', 'whatever', 'except', 'down', 'hers', 'everyone', 'done', 'least', 'another', 'whoever', 'moreover', 'couldnt', 'throughout', 'anyhow', 'yourself', 'three', 'from', 'her', 'few', 'together', 'top', 'there', 'due', 'been', 'next', 'anyone', 'eleven', 'much', 'call', 'therefore', 'interest', 'then', 'thru', 'themselves', 'hundred', 'was', 'sincere', 'empty', 'more', 'himself', 'elsewhere', 'mostly', 'on', 'fire', 'am', 'becoming', 'hereby', 'amongst', 'else', 'part', 'everywhere', 'too', 'herself', 'former', 'those', 'he', 'me', 'myself', 'made', 'twenty', 'these', 'bill', 'cant', 'us', 'until', 'besides', 'nevertheless', 'below', 'anywhere', 'nine', 'can', 'of', 'your', 'toward', 'my', 'something', 'and', 'whereafter', 'whenever', 'give', 'almost', 'wherever', 'is', 'describe', 'beforehand', 'herein', 'an', 'as', 'itself', 'at', 'have', 'in', 'seem', 'whence', 'ie', 'any', 'fill', 'again', 'hasnt', 'inc', 'thereby', 'thin', 'no', 'perhaps', 'latter', 'meanwhile', 'when', 'detail', 'same', 'wherein', 'beside', 'also', 'that', 'other', 'take', 'which', 'becomes', 'you', 'if', 'nobody', 'see', 'though', 'may', 'after', 'upon', 'most', 'hereupon', 'eight', 'but', 'serious', 'nothing', 'such', 'why', 'a', 'off', 'whereby', 'third', 'i', 'whole', 'noone', 'sometimes', 'well', 'amoungst', 'yours', 'their', 'rather', 'without', 'so', 'five', 'the', 'first', 'whereas', 'once']\n", "\n", - "# Write your code below\n" + "# Write your code below\n", + "\n", + "docs = ['doc1.txt', 'doc2.txt', 'doc3.txt']\n", + "\n", + "import os\n", + "\n", + "corpus = []\n", + "\n", + "for file in docs:\n", + " with open(file, 'r') as f:\n", + " content = f.read()\n", + " corpus.append(content)\n", + " \n", + "print(corpus)\n", + " \n", + "deletion_symbol = \".\"\n", + "\n", + "processed_corpus = []\n", + "\n", + "for doc in corpus:\n", + " processed_doc = doc.lower().replace(deletion_symbol, '')\n", + " processed_corpus.append(processed_doc)\n", + " \n", + "print(processed_corpus)\n", + " \n", + "bag_of_words = []\n", + "\n", + "for doc in processed_corpus:\n", + " words = doc.split()\n", + " for word in words:\n", + " if word not in bag_of_words and word not in stop_words:\n", + " bag_of_words.append(word)\n", + " \n", + "print(bag_of_words)\n", + "\n", + "term_freq = []\n", + "\n", + "for doc in processed_corpus:\n", + " words = doc.split()\n", + " freq_counts = []\n", + " for word in bag_of_words:\n", + " freq = words.count(word)\n", + " freq_counts.append(freq)\n", + " term_freq.append(freq_counts)\n", + "\n", + "print(term_freq)" ] }, { @@ -294,6 +431,43 @@ " ```" ] }, + { + "cell_type": "code", + "execution_count": 87, + "metadata": {}, + "outputs": [], + "source": [ + "import sklearn" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1 0 0 1]\n", + " [0 1 0 1]\n", + " [0 0 1 1]]\n" + ] + } + ], + "source": [ + "docs = ['doc1.txt', 'doc2.txt', 'doc3.txt']\n", + "stop_words = ['all', 'six', 'less', 'being', 'indeed', 'over', 'move', 'anyway', 'fifty', 'four', 'not', 'own', 'through', 'yourselves', 'go', 'where', 'mill', 'only', 'find', 'before', 'one', 'whose', 'system', 'how', 'somewhere', 'with', 'thick', 'show', 'had', 'enough', 'should', 'to', 'must', 'whom', 'seeming', 'under', 'ours', 'has', 'might', 'thereafter', 'latterly', 'do', 'them', 'his', 'around', 'than', 'get', 'very', 'de', 'none', 'cannot', 'every', 'whether', 'they', 'front', 'during', 'thus', 'now', 'him', 'nor', 'name', 'several', 'hereafter', 'always', 'who', 'cry', 'whither', 'this', 'someone', 'either', 'each', 'become', 'thereupon', 'sometime', 'side', 'two', 'therein', 'twelve', 'because', 'often', 'ten', 'our', 'eg', 'some', 'back', 'up', 'namely', 'towards', 'are', 'further', 'beyond', 'ourselves', 'yet', 'out', 'even', 'will', 'what', 'still', 'for', 'bottom', 'mine', 'since', 'please', 'forty', 'per', 'its', 'everything', 'behind', 'un', 'above', 'between', 'it', 'neither', 'seemed', 'ever', 'across', 'she', 'somehow', 'be', 'we', 'full', 'never', 'sixty', 'however', 'here', 'otherwise', 'were', 'whereupon', 'nowhere', 'although', 'found', 'alone', 're', 'along', 'fifteen', 'by', 'both', 'about', 'last', 'would', 'anything', 'via', 'many', 'could', 'thence', 'put', 'against', 'keep', 'etc', 'amount', 'became', 'ltd', 'hence', 'onto', 'or', 'con', 'among', 'already', 'co', 'afterwards', 'formerly', 'within', 'seems', 'into', 'others', 'while', 'whatever', 'except', 'down', 'hers', 'everyone', 'done', 'least', 'another', 'whoever', 'moreover', 'couldnt', 'throughout', 'anyhow', 'yourself', 'three', 'from', 'her', 'few', 'together', 'top', 'there', 'due', 'been', 'next', 'anyone', 'eleven', 'much', 'call', 'therefore', 'interest', 'then', 'thru', 'themselves', 'hundred', 'was', 'sincere', 'empty', 'more', 'himself', 'elsewhere', 'mostly', 'on', 'fire', 'am', 'becoming', 'hereby', 'amongst', 'else', 'part', 'everywhere', 'too', 'herself', 'former', 'those', 'he', 'me', 'myself', 'made', 'twenty', 'these', 'bill', 'cant', 'us', 'until', 'besides', 'nevertheless', 'below', 'anywhere', 'nine', 'can', 'of', 'your', 'toward', 'my', 'something', 'and', 'whereafter', 'whenever', 'give', 'almost', 'wherever', 'is', 'describe', 'beforehand', 'herein', 'an', 'as', 'itself', 'at', 'have', 'in', 'seem', 'whence', 'ie', 'any', 'fill', 'again', 'hasnt', 'inc', 'thereby', 'thin', 'no', 'perhaps', 'latter', 'meanwhile', 'when', 'detail', 'same', 'wherein', 'beside', 'also', 'that', 'other', 'take', 'which', 'becomes', 'you', 'if', 'nobody', 'see', 'though', 'may', 'after', 'upon', 'most', 'hereupon', 'eight', 'but', 'serious', 'nothing', 'such', 'why', 'a', 'off', 'whereby', 'third', 'i', 'whole', 'noone', 'sometimes', 'well', 'amoungst', 'yours', 'their', 'rather', 'without', 'so', 'five', 'the', 'first', 'whereas', 'once']\n", + "\n", + "from sklearn.feature_extraction.text import CountVectorizer\n", + "\n", + "vectorizer = CountVectorizer(stop_words=stop_words)\n", + "\n", + "bag_of_words = vectorizer.fit_transform(docs)\n", + "\n", + "print(bag_of_words.toarray())\n" + ] + }, { "cell_type": "code", "execution_count": null, @@ -304,7 +478,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -318,7 +492,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.10.9" } }, "nbformat": 4, From 77fe48d9b20c86194381aeaa1fdffc1bd7033c9a Mon Sep 17 00:00:00 2001 From: ArisGoulas Date: Tue, 20 Jun 2023 17:27:22 +0100 Subject: [PATCH 2/2] lab revised after bootcamp --- your-code/challenge-1.ipynb | 145 ++++++++++------------- your-code/challenge-2.ipynb | 225 ++++++++++++++---------------------- 2 files changed, 151 insertions(+), 219 deletions(-) diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index e09fe55..8c19739 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -33,22 +33,24 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 3, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Durante un tiempo no estuvo segura de si su marido era su marido.\n" - ] + "data": { + "text/plain": [ + "'Durante un tiempo no estuvo segura de si su marido era su marido.'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ "str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", - "# Your code here:\n", - "comb_list = \" \".join(str_list) + \".\"\n", - "print(comb_list)" + "\n", + "\" \".join(str_list) + \".\"" ] }, { @@ -60,24 +62,24 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 5, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "Grocery list: bananas, bread, brownie mix, broccoli.\n" - ] + "data": { + "text/plain": [ + "'Grocery list: bananas, bread, brownie mix, broccoli.'" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", - "# Your code here:\n", - "food_lower = [food.lower() for food in food_list]\n", "\n", - "grocery_list = \"Grocery list: \" + \", \".join([food for food in food_lower if food.startswith(\"b\")]) + \".\"\n", - "print(grocery_list)" + "\"Grocery list: \" + \", \".join([food.lower() for food in food_list if food.lower().startswith(\"b\")]) + \".\"" ] }, { @@ -91,15 +93,18 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 17, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "The area of the circle with radius: 4.5 is: 63.61725123519331.\n" - ] + "data": { + "text/plain": [ + "'The area of the circle with radius: 4.5 is: 63.61725124'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -117,12 +122,9 @@ " # Sample input: 5.0\n", " # Sample Output: 78.53981633\n", " \n", - " # Your code here:\n", - " return pi * (x**2)\n", + " return round(pi * (x**2), 8)\n", " \n", - "# Your output string here:\n", - "area = string1 + \" \" + str(radius) + \" \" + string2 + \" \" + str(area(radius)) + \".\"\n", - "print(area)" + "f\"{string1} {radius} {string2} {area(radius)}\"" ] }, { @@ -138,15 +140,14 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'some', 'say', 'in', 'ice', 'from', 'what', 'i’ve', 'tasted', 'of', 'desire', 'i', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'but', 'if', 'it', 'had', 'to', 'perish', 'twice', 'i', 'think', 'i', 'know', 'enough', 'of', 'hate', 'to', 'say', 'that', 'for', 'destruction', 'ice', 'is', 'also', 'great', 'and', 'would', 'suffice']\n", - "{'some': 2, 'say': 3, 'the': 1, 'world': 1, 'will': 1, 'end': 1, 'in': 2, 'fire': 2, 'ice': 2, 'from': 1, 'what': 1, 'i’ve': 1, 'tasted': 1, 'of': 2, 'desire': 1, 'i': 3, 'hold': 1, 'with': 1, 'those': 1, 'who': 1, 'favor': 1, 'but': 1, 'if': 1, 'it': 1, 'had': 1, 'to': 2, 'perish': 1, 'twice': 1, 'think': 1, 'know': 1, 'enough': 1, 'hate': 1, 'that': 1, 'for': 1, 'destruction': 1, 'is': 1, 'also': 1, 'great': 1, 'and': 1, 'would': 1, 'suffice': 1}\n" + "{'Some': 2, 'say': 3, 'the': 1, 'world': 1, 'will': 1, 'end': 1, 'in': 2, 'fire': 2, 'ice': 2, 'From': 1, 'what': 1, 'I’ve': 1, 'tasted': 1, 'of': 2, 'desire': 1, 'I': 3, 'hold': 1, 'with': 1, 'those': 1, 'who': 1, 'favor': 1, 'But': 1, 'if': 1, 'it': 1, 'had': 1, 'to': 1, 'perish': 1, 'twice': 1, 'think': 1, 'know': 1, 'enough': 1, 'hate': 1, 'To': 1, 'that': 1, 'for': 1, 'destruction': 1, 'Is': 1, 'also': 1, 'great': 1, 'And': 1, 'would': 1, 'suffice': 1}\n" ] } ], @@ -161,21 +162,10 @@ "Is also great\n", "And would suffice.\"\"\"\n", "\n", - "# Your code here:\n", - "clean_string = poem.replace('.', '').replace(',', '').replace('\\n', ' ').lower()\n", - "split_string = clean_string.split(' ')\n", - "\n", - "print(split_string)\n", + "word_list = poem.replace(\",\", \"\").replace(\".\", \"\").replace(\"\\n\", \" \").split()\n", "\n", - "word_count = {}\n", - "\n", - "for word in split_string: \n", - " if word in word_count: \n", - " word_count[word] += 1\n", - " else: \n", - " word_count[word] = 1\n", - "\n", - "print(word_count)" + "word_freq_dict = {word:word_list.count(word) for word in word_list}\n", + "print(word_freq_dict)" ] }, { @@ -187,16 +177,14 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "98\n", - "78\n", - "['i', 'was', 'angry', 'with', 'my', 'friend', 'i', 'told', 'my', 'wrath', 'my', 'wrath', 'did', 'end', 'i', 'was', 'angry', 'with', 'my', 'foe', 'i', 'told', 'not', 'my', 'wrath', 'did', 'grow', 'i', 'waterd', 'fearsnight', '&', 'morning', 'with', 'my', 'tears', 'i', 'sunned', 'with', 'smilesand', 'with', 'soft', 'deceitful', 'wiles', 'grew', 'both', 'day', 'night', 'till', 'bore', 'apple', 'bright', 'my', 'foe', 'beheld', 'shineand', 'he', 'knew', 'that', 'was', 'mine', 'into', 'my', 'garden', 'stole', 'when', 'night', 'had', 'veild', 'pole', 'morning', 'glad', 'i', 'see', 'my', 'foe', 'outstretched', 'beneath', 'tree']\n" + "['i', 'was', 'angry', 'with', 'my', 'friend', 'i', 'told', 'my', 'wrath', 'my', 'wrath', 'did', 'end', 'i', 'was', 'angry', 'with', 'my', 'foe', 'i', 'told', 'not', 'my', 'wrath', 'did', 'grow', 'i', 'waterd', 'fears', 'night', 'morning', 'with', 'my', 'tears', 'i', 'sunned', 'with', 'smiles', 'with', 'soft', 'deceitful', 'wiles', 'grew', 'both', 'day', 'night', 'till', 'bore', 'apple', 'bright', 'my', 'foe', 'beheld', 'shine', 'he', 'knew', 'that', 'was', 'mine', 'into', 'my', 'garden', 'stole', 'when', 'night', 'had', 'veild', 'pole', 'morning', 'glad', 'i', 'see', 'my', 'foe', 'outstretched', 'beneath', 'tree']\n" ] } ], @@ -223,17 +211,10 @@ "In the morning glad I see; \n", "My foe outstretched beneath the tree.\"\"\"\n", "\n", - "# Your code here:\n", - "clean_string = poem.replace('.', ' ').replace(':', '').replace(';', '').replace(',', '').replace('\\n', '').lower()\n", - "split_string = clean_string.split(' ')\n", - "\n", - "remove_empty = [word for word in split_string if word]\n", + "word_list = poem.replace(\";\", \"\").replace(\",\", \"\").replace(\".\", \"\").replace(\":\", \"\").replace(\"&\", \"\").replace(\"\\n\", \" \").lower().split()\n", "\n", - "words_found = [word for word in remove_empty if word not in blacklist]\n", - "\n", - "print(len(remove_empty))\n", - "print(len(words_found))\n", - "print(words_found)" + "whitelist = [word for word in word_list if word not in blacklist]\n", + "print(whitelist)" ] }, { @@ -247,18 +228,15 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 38, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "['T', 'P']" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "['T', 'P']\n" + ] } ], "source": [ @@ -267,8 +245,10 @@ "poem = \"\"\"The apparition of these faces in the crowd;\n", "Petals on a wet, black bough.\"\"\"\n", "\n", - "# Your code here:\n", - "re.findall(\"[A-Z]\", poem)" + "rule_upper = r\"[A-Z]\"\n", + "\n", + "poem_upper = re.findall(rule_upper, poem)\n", + "print(poem_upper)" ] }, { @@ -280,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 46, "metadata": {}, "outputs": [ { @@ -294,9 +274,10 @@ "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", "\n", - "# Your code here:\n", - "contains_number = [x for x in data if re.search(\"[0-9]+\", x)]\n", - "print(contains_number)" + "rule_number = r\"\\d\" # I could also do rule_number = \"[0-9]\"\n", + "\n", + "data_number = [element for element in data if re.search(rule_number, element) is not None]\n", + "print(data_number)" ] }, { @@ -312,7 +293,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 50, "metadata": {}, "outputs": [ { @@ -325,9 +306,11 @@ ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", - "# Your code here:\n", - "filtered_list = [x for x in data if (re.search(\"[0-9]+\", x) and re.search(\"[a-z]+\", x))]\n", - "print(filtered_list)" + "\n", + "rule = r\"(\\d+.*[a-z]+)|([a-z]+.*\\d+)\"\n", + "\n", + "data_number_lower = [element for element in data if (re.search(rule, element)) is not None]\n", + "print(data_number_lower)" ] }, { @@ -354,7 +337,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.9" + "version": "3.10.10" } }, "nbformat": 4, diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 13561bf..3e1045e 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -72,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -88,29 +88,16 @@ }, { "cell_type": "code", - "execution_count": 77, + "execution_count": 3, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" - ] - } - ], + "outputs": [], "source": [ - "# Write your code here\n", - "import os\n", - "\n", "corpus = []\n", "\n", - "for file in docs:\n", - " with open(file, 'r') as f:\n", - " content = f.read()\n", - " corpus.append(content)\n", - " \n", - "print(corpus)" + "for doc in docs:\n", + " f = open(doc)\n", + " corpus.append(f.read())\n", + " f.close()" ] }, { @@ -122,7 +109,7 @@ }, { "cell_type": "code", - "execution_count": 78, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -160,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": 79, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -172,16 +159,8 @@ } ], "source": [ - "# Write your code here\n", - "deletion_symbol = \".\"\n", - "\n", - "processed_corpus = []\n", - "\n", - "for doc in corpus:\n", - " processed_doc = doc.lower().replace(deletion_symbol, '')\n", - " processed_corpus.append(processed_doc)\n", - "\n", - "print(processed_corpus)" + "corpus = [element.lower().replace(\".\",\"\") for element in corpus]\n", + "print(corpus)" ] }, { @@ -193,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": 80, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -213,26 +192,15 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": 8, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['ironhack', 'is', 'cool', 'i', 'love', 'am', 'a', 'student', 'at']\n" - ] - } - ], + "outputs": [], "source": [ - "# Write your code here\n", - "for doc in processed_corpus:\n", - " words = doc.split()\n", - " for word in words:\n", - " if word not in bag_of_words:\n", - " bag_of_words.append(word)\n", - " \n", - "print(bag_of_words)" + "for element in corpus:\n", + " terms_list = element.split()\n", + " for term in terms_list:\n", + " if term not in bag_of_words:\n", + " bag_of_words.append(term)" ] }, { @@ -248,10 +216,20 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 9, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['ironhack', 'is', 'cool', 'i', 'love', 'am', 'a', 'student', 'at']\n" + ] + } + ], + "source": [ + "print(bag_of_words)" + ] }, { "cell_type": "markdown", @@ -262,30 +240,17 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 14, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[[1, 1, 1, 0, 0, 0, 0, 0, 0], [1, 0, 0, 1, 1, 0, 0, 0, 0], [1, 0, 0, 1, 0, 1, 1, 1, 1]]\n" - ] - } - ], + "outputs": [], "source": [ - "# Write your code here\n", "term_freq = []\n", "\n", - "for doc in processed_corpus:\n", - " words = doc.split()\n", - " freq_counts = []\n", - " for word in bag_of_words:\n", - " freq = words.count(word)\n", - " freq_counts.append(freq)\n", - " term_freq.append(freq_counts)\n", - "\n", - "print(term_freq)" + "for element in corpus:\n", + " freq = []\n", + " for term in bag_of_words:\n", + " freq.append(element.split().count(term))\n", + " term_freq.append(freq)" ] }, { @@ -299,10 +264,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1, 1, 1, 0, 0, 0, 0, 0, 0], [1, 0, 0, 1, 1, 0, 0, 0, 0], [1, 0, 0, 1, 0, 1, 1, 1, 1]]\n" + ] + } + ], + "source": [ + "print(term_freq)" + ] }, { "cell_type": "markdown", @@ -337,15 +312,13 @@ }, { "cell_type": "code", - "execution_count": 86, + "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n", - "['ironhack is cool', 'i love ironhack', 'i am a student at ironhack']\n", "['ironhack', 'cool', 'love', 'student']\n", "[[1, 1, 0, 0], [1, 0, 1, 0], [1, 0, 0, 1]]\n" ] @@ -354,51 +327,23 @@ "source": [ "stop_words = ['all', 'six', 'less', 'being', 'indeed', 'over', 'move', 'anyway', 'fifty', 'four', 'not', 'own', 'through', 'yourselves', 'go', 'where', 'mill', 'only', 'find', 'before', 'one', 'whose', 'system', 'how', 'somewhere', 'with', 'thick', 'show', 'had', 'enough', 'should', 'to', 'must', 'whom', 'seeming', 'under', 'ours', 'has', 'might', 'thereafter', 'latterly', 'do', 'them', 'his', 'around', 'than', 'get', 'very', 'de', 'none', 'cannot', 'every', 'whether', 'they', 'front', 'during', 'thus', 'now', 'him', 'nor', 'name', 'several', 'hereafter', 'always', 'who', 'cry', 'whither', 'this', 'someone', 'either', 'each', 'become', 'thereupon', 'sometime', 'side', 'two', 'therein', 'twelve', 'because', 'often', 'ten', 'our', 'eg', 'some', 'back', 'up', 'namely', 'towards', 'are', 'further', 'beyond', 'ourselves', 'yet', 'out', 'even', 'will', 'what', 'still', 'for', 'bottom', 'mine', 'since', 'please', 'forty', 'per', 'its', 'everything', 'behind', 'un', 'above', 'between', 'it', 'neither', 'seemed', 'ever', 'across', 'she', 'somehow', 'be', 'we', 'full', 'never', 'sixty', 'however', 'here', 'otherwise', 'were', 'whereupon', 'nowhere', 'although', 'found', 'alone', 're', 'along', 'fifteen', 'by', 'both', 'about', 'last', 'would', 'anything', 'via', 'many', 'could', 'thence', 'put', 'against', 'keep', 'etc', 'amount', 'became', 'ltd', 'hence', 'onto', 'or', 'con', 'among', 'already', 'co', 'afterwards', 'formerly', 'within', 'seems', 'into', 'others', 'while', 'whatever', 'except', 'down', 'hers', 'everyone', 'done', 'least', 'another', 'whoever', 'moreover', 'couldnt', 'throughout', 'anyhow', 'yourself', 'three', 'from', 'her', 'few', 'together', 'top', 'there', 'due', 'been', 'next', 'anyone', 'eleven', 'much', 'call', 'therefore', 'interest', 'then', 'thru', 'themselves', 'hundred', 'was', 'sincere', 'empty', 'more', 'himself', 'elsewhere', 'mostly', 'on', 'fire', 'am', 'becoming', 'hereby', 'amongst', 'else', 'part', 'everywhere', 'too', 'herself', 'former', 'those', 'he', 'me', 'myself', 'made', 'twenty', 'these', 'bill', 'cant', 'us', 'until', 'besides', 'nevertheless', 'below', 'anywhere', 'nine', 'can', 'of', 'your', 'toward', 'my', 'something', 'and', 'whereafter', 'whenever', 'give', 'almost', 'wherever', 'is', 'describe', 'beforehand', 'herein', 'an', 'as', 'itself', 'at', 'have', 'in', 'seem', 'whence', 'ie', 'any', 'fill', 'again', 'hasnt', 'inc', 'thereby', 'thin', 'no', 'perhaps', 'latter', 'meanwhile', 'when', 'detail', 'same', 'wherein', 'beside', 'also', 'that', 'other', 'take', 'which', 'becomes', 'you', 'if', 'nobody', 'see', 'though', 'may', 'after', 'upon', 'most', 'hereupon', 'eight', 'but', 'serious', 'nothing', 'such', 'why', 'a', 'off', 'whereby', 'third', 'i', 'whole', 'noone', 'sometimes', 'well', 'amoungst', 'yours', 'their', 'rather', 'without', 'so', 'five', 'the', 'first', 'whereas', 'once']\n", "\n", - "# Write your code below\n", - "\n", - "docs = ['doc1.txt', 'doc2.txt', 'doc3.txt']\n", - "\n", - "import os\n", - "\n", - "corpus = []\n", - "\n", - "for file in docs:\n", - " with open(file, 'r') as f:\n", - " content = f.read()\n", - " corpus.append(content)\n", - " \n", - "print(corpus)\n", - " \n", - "deletion_symbol = \".\"\n", - "\n", - "processed_corpus = []\n", - "\n", - "for doc in corpus:\n", - " processed_doc = doc.lower().replace(deletion_symbol, '')\n", - " processed_corpus.append(processed_doc)\n", - " \n", - "print(processed_corpus)\n", - " \n", "bag_of_words = []\n", "\n", - "for doc in processed_corpus:\n", - " words = doc.split()\n", - " for word in words:\n", - " if word not in bag_of_words and word not in stop_words:\n", - " bag_of_words.append(word)\n", + "for element in corpus:\n", + " terms_list = element.split()\n", + " for term in terms_list:\n", + " if (term not in bag_of_words) and (term not in stop_words):\n", + " bag_of_words.append(term)\n", " \n", - "print(bag_of_words)\n", - "\n", "term_freq = []\n", "\n", - "for doc in processed_corpus:\n", - " words = doc.split()\n", - " freq_counts = []\n", - " for word in bag_of_words:\n", - " freq = words.count(word)\n", - " freq_counts.append(freq)\n", - " term_freq.append(freq_counts)\n", - "\n", + "for element in corpus:\n", + " freq = []\n", + " for term in bag_of_words:\n", + " freq.append(element.split().count(term))\n", + " term_freq.append(freq)\n", + " \n", + "print(bag_of_words)\n", "print(term_freq)" ] }, @@ -433,39 +378,43 @@ }, { "cell_type": "code", - "execution_count": 87, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'ironhack': 3, 'is': 4, 'cool': 2, 'love': 5, 'am': 0, 'student': 6, 'at': 1}\n" + ] + } + ], "source": [ - "import sklearn" + "from sklearn.feature_extraction.text import CountVectorizer\n", + "\n", + "vectorizer = CountVectorizer()\n", + "X = vectorizer.fit_transform(corpus)\n", + "\n", + "print(vectorizer.vocabulary_)" ] }, { "cell_type": "code", - "execution_count": 90, + "execution_count": 21, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[[1 0 0 1]\n", - " [0 1 0 1]\n", - " [0 0 1 1]]\n" + "[[0 0 1 1 1 0 0]\n", + " [0 0 0 1 0 1 0]\n", + " [1 1 0 1 0 0 1]]\n" ] } ], "source": [ - "docs = ['doc1.txt', 'doc2.txt', 'doc3.txt']\n", - "stop_words = ['all', 'six', 'less', 'being', 'indeed', 'over', 'move', 'anyway', 'fifty', 'four', 'not', 'own', 'through', 'yourselves', 'go', 'where', 'mill', 'only', 'find', 'before', 'one', 'whose', 'system', 'how', 'somewhere', 'with', 'thick', 'show', 'had', 'enough', 'should', 'to', 'must', 'whom', 'seeming', 'under', 'ours', 'has', 'might', 'thereafter', 'latterly', 'do', 'them', 'his', 'around', 'than', 'get', 'very', 'de', 'none', 'cannot', 'every', 'whether', 'they', 'front', 'during', 'thus', 'now', 'him', 'nor', 'name', 'several', 'hereafter', 'always', 'who', 'cry', 'whither', 'this', 'someone', 'either', 'each', 'become', 'thereupon', 'sometime', 'side', 'two', 'therein', 'twelve', 'because', 'often', 'ten', 'our', 'eg', 'some', 'back', 'up', 'namely', 'towards', 'are', 'further', 'beyond', 'ourselves', 'yet', 'out', 'even', 'will', 'what', 'still', 'for', 'bottom', 'mine', 'since', 'please', 'forty', 'per', 'its', 'everything', 'behind', 'un', 'above', 'between', 'it', 'neither', 'seemed', 'ever', 'across', 'she', 'somehow', 'be', 'we', 'full', 'never', 'sixty', 'however', 'here', 'otherwise', 'were', 'whereupon', 'nowhere', 'although', 'found', 'alone', 're', 'along', 'fifteen', 'by', 'both', 'about', 'last', 'would', 'anything', 'via', 'many', 'could', 'thence', 'put', 'against', 'keep', 'etc', 'amount', 'became', 'ltd', 'hence', 'onto', 'or', 'con', 'among', 'already', 'co', 'afterwards', 'formerly', 'within', 'seems', 'into', 'others', 'while', 'whatever', 'except', 'down', 'hers', 'everyone', 'done', 'least', 'another', 'whoever', 'moreover', 'couldnt', 'throughout', 'anyhow', 'yourself', 'three', 'from', 'her', 'few', 'together', 'top', 'there', 'due', 'been', 'next', 'anyone', 'eleven', 'much', 'call', 'therefore', 'interest', 'then', 'thru', 'themselves', 'hundred', 'was', 'sincere', 'empty', 'more', 'himself', 'elsewhere', 'mostly', 'on', 'fire', 'am', 'becoming', 'hereby', 'amongst', 'else', 'part', 'everywhere', 'too', 'herself', 'former', 'those', 'he', 'me', 'myself', 'made', 'twenty', 'these', 'bill', 'cant', 'us', 'until', 'besides', 'nevertheless', 'below', 'anywhere', 'nine', 'can', 'of', 'your', 'toward', 'my', 'something', 'and', 'whereafter', 'whenever', 'give', 'almost', 'wherever', 'is', 'describe', 'beforehand', 'herein', 'an', 'as', 'itself', 'at', 'have', 'in', 'seem', 'whence', 'ie', 'any', 'fill', 'again', 'hasnt', 'inc', 'thereby', 'thin', 'no', 'perhaps', 'latter', 'meanwhile', 'when', 'detail', 'same', 'wherein', 'beside', 'also', 'that', 'other', 'take', 'which', 'becomes', 'you', 'if', 'nobody', 'see', 'though', 'may', 'after', 'upon', 'most', 'hereupon', 'eight', 'but', 'serious', 'nothing', 'such', 'why', 'a', 'off', 'whereby', 'third', 'i', 'whole', 'noone', 'sometimes', 'well', 'amoungst', 'yours', 'their', 'rather', 'without', 'so', 'five', 'the', 'first', 'whereas', 'once']\n", - "\n", - "from sklearn.feature_extraction.text import CountVectorizer\n", - "\n", - "vectorizer = CountVectorizer(stop_words=stop_words)\n", - "\n", - "bag_of_words = vectorizer.fit_transform(docs)\n", - "\n", - "print(bag_of_words.toarray())\n" + "print(X.toarray())" ] }, { @@ -492,7 +441,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.9" + "version": "3.10.10" } }, "nbformat": 4,