diff --git a/AD450_math.py b/AD450_math.py new file mode 100644 index 0000000..481036f --- /dev/null +++ b/AD450_math.py @@ -0,0 +1,6 @@ +def add(num1, num2): + return num1 + num2 + +def multiply(num1, num2): + return num1 * num2 + diff --git a/week_2_intro_ipython.ipynb b/week_2_intro_ipython.ipynb index 1a469f7..e6bf222 100644 --- a/week_2_intro_ipython.ipynb +++ b/week_2_intro_ipython.ipynb @@ -24,12 +24,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "BQybla17FRh5" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My name is Joe.\n", + "I am a student at North Seattle College.\n" + ] + } + ], + "source": [ + "print(f\"My name is Joe.\\nI am a student at North Seattle College.\")" + ] }, { "cell_type": "markdown", @@ -43,12 +54,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "id": "P7QDyWncFRh8" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My phone number is 2065555555\n" + ] + } + ], + "source": [ + "phone_num = \"2065555555\"\n", + "\n", + "print(f\"My phone number is {phone_num}\")" + ] }, { "cell_type": "markdown", @@ -62,12 +85,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "id": "OnOau948FRh9" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello my name is Joe and my phone number is 206-555-5555\n" + ] + } + ], + "source": [ + "phone = \"206-555-5555\"\n", + "name = \"Joe\"\n", + "\n", + "print(f\"Hello my name is {name} and my phone number is {phone}\")" + ] }, { "cell_type": "markdown", @@ -82,12 +118,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "id": "5x2rIFzRFRh9" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I graduate in June of 2027.\n" + ] + } + ], + "source": [ + "month, year = \"June\", 2027\n", + "\n", + "print(f\"I graduate in {month} of {year}.\")" + ] }, { "cell_type": "markdown", @@ -109,12 +157,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "OkyeAVPXFRh-" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ans = 58.5\n" + ] + } + ], + "source": [ + "ans = 12 * 5 - 3 / 2\n", + "ans_type = str(type(ans))\n", + "\n", + "print(f\"ans = {ans}\")\n", + "\n", + "# ans is a float" + ] }, { "cell_type": "markdown", @@ -136,12 +199,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": { "id": "Lo-LEy8bKYmG" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "31 days\n" + ] + } + ], + "source": [ + "oct = \"October\"\n", + "\n", + "if oct == \"October\":\n", + " print(\"31 days\")\n", + "else:\n", + " print(\"30 days\")" + ] }, { "cell_type": "markdown", @@ -157,12 +235,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "id": "qscUkh813QKH" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "between 100 and 150\n" + ] + } + ], + "source": [ + "x = 140\n", + "\n", + "if x > 150:\n", + " print(\"greater than 150\")\n", + "elif x > 100 and x < 150:\n", + " print(\"between 100 and 150\")\n", + "else:\n", + " print(\"less than 100\")" + ] }, { "cell_type": "markdown", @@ -177,12 +272,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": { "id": "1vxg4nMbFRh_" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number is divisible by 5 and 10.\n", + "Number is divisible by 7 or by 2\n" + ] + } + ], + "source": [ + "y = 70\n", + "\n", + "# you only need to check for mod 10 below becuase if it is divisible by 10 then \n", + "# it is also divisible by 5\n", + "if y % 10 == 0:\n", + " print(\"Number is divisible by 5 and 10.\")\n", + "\n", + "if y % 7 == 0 or y % 2 == 0:\n", + " print(\"Number is divisible by 7 or by 2\")\n" + ] }, { "cell_type": "markdown", @@ -195,12 +309,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "JY_Ci5v-FRiA" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "7\n", + "14\n", + "21\n", + "28\n", + "35\n", + "42\n", + "49\n", + "56\n", + "63\n", + "70\n", + "77\n", + "84\n", + "91\n", + "98\n" + ] + } + ], + "source": [ + "for i in range(1,101):\n", + " if i % 7 == 0:\n", + " print(i)" + ] }, { "cell_type": "markdown", @@ -213,12 +352,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "id": "4a1D64hpFRiA" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3 6 9 \n", + "18\n" + ] + } + ], + "source": [ + "sum = 0\n", + "i = 1\n", + "\n", + "while i < 11:\n", + " if i % 3 == 0:\n", + " print(i, end= \" \")\n", + " sum += i\n", + " i += 1\n", + "\n", + "print(f\"\\n{sum}\")" + ] }, { "cell_type": "markdown", @@ -241,12 +400,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": { "id": "ntBnYxzi1RPc" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Set: 1\n", + "Set: 2\n", + "Student: 1\n", + "Student: 2\n", + "Student: 3\n", + "Student: 4\n", + "Student: 5\n", + "Set: 3\n", + "Set: 4\n", + "Student: 1\n", + "Student: 2\n", + "Student: 3\n", + "Student: 4\n", + "Student: 5\n", + "Set: 5\n" + ] + } + ], + "source": [ + "for i in range(1,6):\n", + " print(f\"Set: {i}\")\n", + " if i % 2 == 0:\n", + " for j in range(1,6):\n", + " print(f\"Student: {j}\")" + ] }, { "cell_type": "markdown", @@ -259,12 +446,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "id": "lppms8ctzfRI" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hog\n", + "warts\n", + "s\n" + ] + } + ], + "source": [ + "school = \"Hogwarts\"\n", + "first = school[:3]\n", + "second = school[3:]\n", + "\n", + "print(first)\n", + "print(second)\n", + "print(school[-1])" + ] }, { "cell_type": "markdown", @@ -280,12 +485,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "id": "zw2NezoM0zfl" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Thor is a character in the Marvel Cinematic Universe. She-Hulk is a character in the Marvel Cinematic Universe. Loki is a character in the Marvel Cinematic Universe. " + ] + } + ], + "source": [ + "chars = [\"Thor\", \"She-Hulk\", \"Loki\"]\n", + "\n", + "for name in chars:\n", + " print(f\"{name} is a character in the Marvel Cinematic Universe.\", end = \" \")\n" + ] }, { "cell_type": "markdown", @@ -299,12 +517,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "id": "rbyZif9a1b2V" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "January has 31 days. \n", + "February has 28 days. \n", + "March has 31 days. \n", + "April has 30 days. \n", + "May has 31 days. \n", + "June has 30 days. \n" + ] + } + ], + "source": [ + "months = [[\"January\", 31], [\"February\", 28], [\"March\", 31], [\"April\", 30], [\"May\", 31], [\"June\", 30]]\n", + "\n", + "for i in range(len(months)):\n", + " month, days = months[i][0], months[i][1]\n", + " print(f\"{month} has {days} days. \")" + ] }, { "cell_type": "markdown", @@ -325,8 +562,38 @@ "metadata": { "id": "p0YE0nqs4Hcz" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'breed': 'Corgi', 'Age Exp.': 13, 'Type': 'Cattle herding'}\n", + "Corgi\n", + "The Corgi is expected to live about 13 years.\n" + ] + } + ], + "source": [ + "dog = {\"breed\": \"Corgi\", \"Age Exp.\": 13, \"Type\": \"Cattle herding\"}\n", + "\n", + "print(dog)\n", + "\n", + "print(dog[\"breed\"])\n", + "\n", + "print(f\"The {dog['breed']} is expected to live about {dog['Age Exp.']} years.\")\n", + "\n", + "\"\"\"\n", + "I used AI to help me with this as I kept getting an error on the last print statement \n", + "because I was using double quotes for the variable I was placing inside the f-string. \n", + "I was trying to access it like this dog[\"breed\"] but kept getting an error. So I pasted \n", + "it into gpt and it explained that the interpreter was interpreting the first double \n", + "quotation mark as the end of the f-string. Thus causing the error. \n", + "\n", + "I also learned that juypter notebook is finicky about mutli-line comments and you have \n", + "to add a semi-colon after the second triple quote otherwise it will print your comment. \n", + "\"\"\";\n", + "\n" + ] }, { "cell_type": "markdown", @@ -339,11 +606,22 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import AD450_math\n", "\n", - "AD450_math.add(2,2)" + "AD450_math.add(2,2)\n" ] }, { @@ -359,9 +637,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "AttributeError", + "evalue": "module 'AD450_math' has no attribute 'multiply'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[2], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# Cell with import error\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[43mAD450_math\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmultiply\u001b[49m(\u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m2\u001b[39m)\n", + "\u001b[0;31mAttributeError\u001b[0m: module 'AD450_math' has no attribute 'multiply'" + ] + } + ], "source": [ "# Cell with import error\n", "AD450_math.multiply(2, 2)" @@ -371,16 +661,40 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Reload cell" + "# Reload cell\n", + "import importlib\n", + "importlib.reload(AD450_math)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Cell with correct output \n", "AD450_math.multiply(2, 2)" @@ -400,29 +714,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "# Create a" + "# Create a\n", + "a = 1" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], "source": [ - "# Print a" + "# Print a\n", + "print(a)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "# Set a to 4" + "# Set a to 4\n", + "a = 4\n", + "\n", + "\"\"\" \n", + "It looks like after running this block that it is changing the global value of a. \n", + "so when we run the block above it prints out 4 because a has been re-assigned.\n", + "\"\"\";" ] } ], @@ -431,7 +761,7 @@ "provenance": [] }, "kernelspec": { - "display_name": "my_env_2", + "display_name": "ml-env", "language": "python", "name": "python3" }, @@ -445,7 +775,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.16" + "version": "3.10.18" } }, "nbformat": 4, diff --git a/week_3_numpy.ipynb b/week_3_numpy.ipynb index 1db8573..cd71e72 100644 --- a/week_3_numpy.ipynb +++ b/week_3_numpy.ipynb @@ -20,6 +20,11 @@ "* Can map data directly onto underlying disk or memory representation\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, { "cell_type": "markdown", "metadata": { @@ -57,7 +62,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 3, "metadata": { "id": "Pt63xmy1qLll" }, @@ -75,7 +80,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -83,19 +88,37 @@ "id": "AVByQUYKxtNG", "outputId": "238e50f0-366d-41de-a44a-6cf3e063650c" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1 2 3 4]\n", + " [5 6 7 8]]\n", + "\n", + "Inspect the array\n", + "--------------\n", + "dimensions: 2\n", + "shape:\t (2, 4)\n", + "size:\t 8\n", + "datatype int64\n", + "bytes:\t 64\n" + ] + } + ], "source": [ "# create an array called numbers with 2 rows and 4 columns from literal values. Have your literal values be the integers 1-8\n", - "numbers = None #Replace None with array defintion\n", + "numbers = np.array([[1,2,3,4], [5,6,7,8]])\n", + "\n", "print(numbers)\n", "\n", "# Replace None below with each value for the array. \n", "print(\"\\nInspect the array\\n--------------\")\n", - "print(\"dimensions:\", None) # ndarrays have dimensions\n", - "print(\"shape:\\t\", None) # ndarrays have shape (numer of rows & columns)\n", - "print(\"size:\\t\", None) # number of elements in the array\n", - "print(\"datatype\", None) # numpy determines the datatype\n", - "print(\"bytes:\\t\", None) # total bytes consumed by the array" + "print(\"dimensions:\", numbers.ndim) # ndarrays have dimensions\n", + "print(\"shape:\\t\", numbers.shape) # ndarrays have shape (numer of rows & columns)\n", + "print(\"size:\\t\", numbers.size) # number of elements in the array\n", + "print(\"datatype\", numbers.dtype) # numpy determines the datatype\n", + "print(\"bytes:\\t\", numbers.nbytes) # total bytes consumed by the array" ] }, { @@ -109,7 +132,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -117,34 +140,77 @@ "id": "pTXgMRYRQS3v", "outputId": "010d4702-bc29-4f87-980e-66fe9b43436a" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ones\n", + "[[1. 1. 1. 1.]\n", + " [1. 1. 1. 1.]\n", + " [1. 1. 1. 1.]] \n", + "\n", + "zeros\n", + "[[0. 0. 0. 0.]\n", + " [0. 0. 0. 0.]\n", + " [0. 0. 0. 0.]] \n", + "\n", + "random\n", + "[[0.52286842 0.27818666]\n", + " [1.20170613 0.13236204]] \n", + "\n", + "empty\n", + "[[0. 0.]\n", + " [0. 0.]\n", + " [0. 0.]] \n", + "\n", + "full\n", + "[['x' 'x']\n", + " ['x' 'x']] \n", + "\n", + "even\n", + "[10 15 20] \n", + "\n", + "line\n", + "[0. 0.25 0.5 0.75 1. 1.25 1.5 1.75 2. ] \n", + "\n" + ] + } + ], "source": [ "# Create an 3 by 4 array of ones\n", - "ones = None\n", + "ones = np.ones((3,4))\n", + "print(\"ones\")\n", "print(ones, \"\\n\")\n", "\n", "# Create an 3 by 4 array of zeros\n", - "zeros = None\n", + "zeros = np.zeros((3,4))\n", + "print(\"zeros\")\n", "print(zeros, \"\\n\")\n", "\n", "# Create an 2 by 2 array with random values\n", - "rando = None\n", + "rando = np.random.standard_normal(size = (2,2))\n", + "print(\"random\")\n", "print(rando, \"\\n\")\n", "\n", "# Create 3 by 2 an empty array\n", - "empty = None\n", + "empty = np.empty((3,2))\n", + "print(\"empty\")\n", "print(empty, \"\\n\")\n", "\n", "# Create a 2 by 2 array full of 'x's, hint seach numpy full\n", - "full = None\n", + "full = np.full((2,2),'x')\n", + "print(\"full\")\n", "print(full, \"\\n\")\n", "\n", "# Create an array of the form [10, 15, 20] using np.arange\n", - "even = None\n", + "even = np.arange(10,21,5)\n", + "print(\"even\")\n", "print(even, \"\\n\")\n", "\n", "# Create an array of the form [0. 0.25 0.5 0.75 1. 1.25 1.5 1.75 2. ] using np.linspace\n", - "line = None\n", + "line = np.linspace(0, 2, 9)\n", + "print(\"line\")\n", "print(line, \"\\n\")\n" ] }, @@ -180,11 +246,22 @@ "id": "NSMJt_4x0qan", "outputId": "81e81c55-af1d-4149-dc7c-7edc8a1a582d" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[5 6 7]\n" + ] + } + ], "source": [ "arr1d = np.array([0,1, 2, 3, 4, 5, 6, 7, 8])\n", "\n", - "# using indexing select and output [5, 6, 7] from arr1d. Save this slice to a variable named slice_arr1d\n" + "# using indexing select and output [5, 6, 7] from arr1d. Save this slice to a variable named slice_arr1d\n", + "\n", + "slice_arr1d = arr1d[5:8]\n", + "print(slice_arr1d)\n" ] }, { @@ -204,9 +281,20 @@ "id": "Xe-PXYhBp4bn", "outputId": "cf387d7a-d51f-4540-8d9a-571a9a24f7b5" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 0 1 2 3 4 5 12 12 12]\n" + ] + } + ], "source": [ - "# Replace 6, 7, and 8 with 12 in arr1d using one line of code. Then print arr1d and slice_arr1d\n" + "# Replace 6, 7, and 8 with 12 in arr1d using one line of code. Then print arr1d and slice_arr1d\n", + "\n", + "arr1d[6:] = 12\n", + "print(arr1d)\n" ] }, { @@ -226,9 +314,20 @@ "id": "Eh0My7Eaqe77", "outputId": "693ef4b3-97a0-4a42-d77a-740fa2cd81db" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 0 1 2 3 4 5 12 12 12]\n" + ] + } + ], "source": [ - "# Create a copy of arr1d and name it new_array. Hint: You can't use new_array = arr1d" + "# Create a copy of arr1d and name it new_array. Hint: You can't use new_array = arr1d\n", + "\n", + "new_array = arr1d.copy()\n", + "print(new_array)" ] }, { @@ -240,13 +339,25 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "3\n" + ] + } + ], "source": [ "arr2d = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])\n", "\n", - "# There are two ways to select 3 from the 2 dimensional array above. Use both ways to select 3 and print the results. " + "# There are two ways to select 3 from the 2 dimensional array above. Use both ways to select 3 and print the results. \n", + "\n", + "print(arr2d[0][2])\n", + "print(arr2d[0,2])" ] }, { @@ -266,16 +377,32 @@ "id": "kvMvyar216T5", "outputId": "943f42a4-469a-48f0-f4d4-546849ffa08d" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[2 3 4]\n", + " [6 7 8]] \n", + "\n", + "[3 7] \n", + "\n", + "[1 2 3 4]\n" + ] + } + ], "source": [ "# In mult-dimensional arrays, slicing that omits later indices will return a lower-dimensional ndarray\n", "# Select and print out the following:\n", "\n", "# select first two rows and all but first column\n", + "print(arr2d[:2, 1:], \"\\n\")\n", "\n", "# select first two rows and only 3rd column\n", + "print(arr2d[:2, 2], \"\\n\")\n", "\n", - "# select all columns in the first row\n" + "# select all columns in the first row\n", + "print(arr2d[0, :])\n" ] }, { @@ -298,7 +425,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 12, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -306,14 +433,38 @@ "id": "IMEp_RGh_Fu5", "outputId": "45332ef8-2c42-4c40-af09-6caaf98bca6b" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "First and fourth rows of data: \n", + "[[1 0 0 0 0 1 1]\n", + " [0 1 1 1 0 0 0]] \n", + "\n", + "All of data: \n", + "[[1 0 0 0 0 1 1]\n", + " [1 1 0 1 1 1 1]\n", + " [0 1 0 1 0 0 1]\n", + " [0 1 1 1 0 0 0]\n", + " [1 0 1 0 1 1 1]\n", + " [1 1 1 1 1 0 0]\n", + " [1 0 0 1 0 1 0]]\n" + ] + } + ], "source": [ "import numpy as np\n", "names = np.array(['Bob', 'Joe', 'Will', 'Bob', 'Will', 'Joe', 'Joe'])\n", "data = np.random.randint(2, size=(7, 7)) # create an array of random values\n", "\n", "# Select and print the first and forth rows from 'data' using just the array 'names' and 'data'. Print out both the selected rows and 'data'. \n", - "# Hint\" The \"Bob\" appears in both the first and forth rows. " + "# Hint\" The \"Bob\" appears in both the first and forth rows. \n", + "\n", + "print(\"First and fourth rows of data: \")\n", + "print(data[names == \"Bob\"], \"\\n\")\n", + "print(\"All of data: \")\n", + "print(data)\n" ] }, { @@ -327,7 +478,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -335,10 +486,22 @@ "id": "BgULatpwt7X_", "outputId": "c31d49b4-92ff-4514-c91b-8eeb42573b5f" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1, 0, 0, 0, 0, 1, 1],\n", + " [0, 1, 1, 1, 0, 0, 0]])" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Again output the first and fouth rows using the cond below. Meaning replace None with an expression\n", - "cond = None\n", + "cond = (names == \"Bob\")\n", "data[cond]" ] }, @@ -353,7 +516,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 14, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -361,9 +524,27 @@ "id": "EP-SDDVIvK8s", "outputId": "cce4fab9-cd5e-46c2-c615-f2518f1b4a72" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[1, 1, 0, 1, 1, 1, 1],\n", + " [0, 1, 0, 1, 0, 0, 1],\n", + " [1, 0, 1, 0, 1, 1, 1],\n", + " [1, 1, 1, 1, 1, 0, 0],\n", + " [1, 0, 0, 1, 0, 1, 0]])" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Select all rows except the first and forth" + "# Select all rows except the first and forth\n", + "\n", + "cond = ~(names == \"Bob\")\n", + "data[cond]" ] }, { @@ -377,7 +558,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 15, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -385,9 +566,23 @@ "id": "QYjmF7eFvTmc", "outputId": "172adeb5-31d7-47ad-e3af-59c352f96f97" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0, 0, 0, 1, 1],\n", + " [1, 1, 0, 0, 0]])" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Select the last 5 columns for the first and forth row" + "# Select the last 5 columns for the first and forth row\n", + "cond = (names == \"Bob\")\n", + "data[cond, 2:]" ] }, { @@ -401,7 +596,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 37, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -409,9 +604,26 @@ "id": "sciz0aprvh8u", "outputId": "24c8c092-cbe9-4665-9e01-9d193bcac8df" }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0, 0, 0, 0, 1, 1, 1],\n", + " [1, 0, 0, 0, 1, 0, 1],\n", + " [0, 1, 1, 1, 0, 1, 0],\n", + " [0, 1, 1, 1, 1, 1, 1]])" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Select the first, third, forth and fifth row using similar conditioins and an OR operator" + "# Select the first, third, forth and fifth row using similar conditioins and an OR operator\n", + "\n", + "cond = (names == \"Bob\") | (names == \"Will\")\n", + "data[cond]" ] }, { @@ -436,7 +648,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -444,18 +656,39 @@ "id": "HdWTjc8CZI5R", "outputId": "e070b71e-bdee-4abc-f378-474978208ad5" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original array: \n", + "[[1. 2. 3.]\n", + " [4. 5. 6.]] \n", + "\n", + "Adding 5: \n", + "[[ 6. 7. 8.]\n", + " [ 9. 10. 11.]] \n", + "\n", + "Multiplying by 10: \n", + "[[10. 20. 30.]\n", + " [40. 50. 60.]]\n" + ] + } + ], "source": [ "array1 = np.array([[1., 2., 3.], [4., 5., 6.]])\n", "\n", - "print(array1)\n", + "print(\"Original array: \")\n", + "print(array1, \"\\n\")\n", "\n", "# Add 5 to all values in array1 and print \n", - "print()\n", + "print(\"Adding 5: \")\n", + "print(array1 + 5, \"\\n\")\n", "\n", "\n", "# Multiple all values in array1 by 10 and print \n", - "print()\n" + "print(\"Multiplying by 10: \")\n", + "print(array1 * 10)\n" ] }, { @@ -469,7 +702,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 48, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -477,9 +710,23 @@ "id": "uHr0DxrmaOEZ", "outputId": "b0f74550-427d-4333-c010-45f886677379" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[False True False]\n", + " [ True False True]]\n" + ] + } + ], "source": [ + "# array1 = np.array([[1., 2., 3.], [4., 5., 6.]])\n", + "\n", "array2 = np.array([[0., 4., 1.], [7., 2., 12.]])\n", + "result14 = np.where(array1 < array2, True, False)\n", + "\n", + "print(result14)\n", "\n", "\n", "# Test to see if pairwise elements in array1 are less than the corresponding element in array2. Output the results.\n", @@ -519,7 +766,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 49, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -527,13 +774,25 @@ "id": "k5pIynI12dmY", "outputId": "cd39dc42-7bab-4a92-c3e0-151a287d0b07" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1. 0. 1. 1. 0.]\n" + ] + } + ], "source": [ "arr1 = np.ones(5)\n", "arr2 = np.zeros(5)\n", "cond = np.array([True, False, True, True, False])\n", "\n", - "# Output the value from `arr1` whenever the corresponding value in `cond` is True, and otherwise take the value from `arr2`. \n" + "# Output the value from `arr1` whenever the corresponding value in `cond` is True, and otherwise take the value from `arr2`. \n", + "\n", + "result15 = np.where(cond, arr1, arr2)\n", + "\n", + "print(result15)\n" ] }, { @@ -564,7 +823,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -572,12 +831,33 @@ "id": "ImvBT7NX3aY7", "outputId": "d04b3b76-91e4-4a40-e047-1e7a55bfd4ed" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[0 3 3 3]\n", + " [0 3 1 0]\n", + " [1 1 1 2]\n", + " [3 3 2 0]\n", + " [1 3 2 0]] \n", + "\n", + "Mean: 1.6\n", + "Sum: 32\n" + ] + } + ], "source": [ "arr = np.random.randint(4, size=(5, 4))\n", - "print(arr)\n", + "print(arr, \"\\n\")\n", + "\n", + "# Calculate and print the mean and sum for all values in the array\n", + "\n", + "mean16 = np.mean(arr)\n", + "sum16 = arr.sum()\n", "\n", - "# Calculate and print the mean and sum for all values in the array\n" + "print(\"Mean: \", mean16)\n", + "print(\"Sum: \", sum16)\n" ] }, { @@ -589,7 +869,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" @@ -597,9 +877,32 @@ "id": "kxw7AUVm31Ea", "outputId": "b1cb6ece-5056-41b1-8c1b-f57612b9dae1" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean across rows: [2.25 1. 1.25 2. 1.5 ]\n", + "Mean across columns: [1. 2.6 1.8 1. ]\n", + "Sum across rows: [9 4 5 8 6]\n", + "Sum across columns: [ 5 13 9 5]\n" + ] + } + ], "source": [ - "# Calculate the mean and sum across the columns and the rows. Print out both\n" + "# Calculate the mean and sum across the columns and the rows. Print out both\n", + "# axis = 0 columns \n", + "# axis = 1 rows \n", + "\n", + "mean17_rows = arr.mean(axis = 1)\n", + "mean17_columns = arr.mean(axis = 0)\n", + "sum17_rows = arr.sum(axis = 1)\n", + "sum17_columns = arr.sum(axis = 0)\n", + "\n", + "print(\"Mean across rows: \", mean17_rows)\n", + "print(\"Mean across columns: \", mean17_columns)\n", + "print(\"Sum across rows: \", sum17_rows)\n", + "print(\"Sum across columns: \", sum17_columns)\n" ] }, { @@ -611,15 +914,46 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 25, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Full cummulative sum: \n", + " [ 0 3 6 9 9 12 13 13 14 15 16 18 21 24 26 26 27 30 32 32] \n", + "\n", + "Columns cumulative sum: \n", + " [[ 0 3 3 3]\n", + " [ 0 6 4 3]\n", + " [ 1 7 5 5]\n", + " [ 4 10 7 5]\n", + " [ 5 13 9 5]] \n", + "\n", + "Rows cumulative sum: \n", + " [[0 3 6 9]\n", + " [0 3 4 4]\n", + " [1 2 3 5]\n", + " [3 6 8 8]\n", + " [1 4 6 6]]\n" + ] + } + ], "source": [ "# Print out the cumulative sum for the full array, the columns and the rows. \n", "# For example the array [[1, 1, 1], [1, 1, 1]] would have the following outputs:\n", "# full array: [1, 2, 3, 4, 5, 6]\n", "# columns: [[1, 1, 1], [2, 2, 2]]\n", - "# rows: [[1, 2, 3], [1, 2, 3]]\n" + "# rows: [[1, 2, 3], [1, 2, 3]]\n", + "\n", + "cumsum18_full = arr.cumsum()\n", + "cumsum18_columns = arr.cumsum(axis = 0)\n", + "cumsum18_rows = arr.cumsum(axis = 1)\n", + "\n", + "print(\"Full cummulative sum: \\n\", cumsum18_full, \"\\n\")\n", + "print(\"Columns cumulative sum: \\n\", cumsum18_columns, \"\\n\")\n", + "print(\"Rows cumulative sum: \\n\", cumsum18_rows)\n" ] }, { @@ -639,16 +973,34 @@ "id": "sDnJpvUR1B1W", "outputId": "c4806b83-0ba9-448e-c4b7-f9ca53a8900d" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Arr: \n", + " [0 1 2 3 4 5 6 7 8 9] \n", + "\n", + "Odds: \n", + " [1 3 5 7 9] \n", + "\n", + "Arr reversed: \n", + " [9 8 7 6 5 4 3 2 1 0]\n" + ] + } + ], "source": [ "\n", "arr = np.arange(10)\n", - "print(arr)\n", + "print(\"Arr: \\n\", arr, \"\\n\")\n", "\n", "\n", "# Print out all all odd values\n", + "odds = arr[arr % 2 == 1]\n", + "print(\"Odds: \\n\", odds, \"\\n\")\n", "\n", - "# Print out all values in reverse order\n" + "# Print out all values in reverse order\n", + "print(\"Arr reversed: \\n\", np.flip(arr))\n" ] } ], @@ -664,7 +1016,7 @@ "provenance": [] }, "kernelspec": { - "display_name": "base", + "display_name": "ml-env", "language": "python", "name": "python3" }, @@ -678,7 +1030,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.4" + "version": "3.10.18" } }, "nbformat": 4, diff --git a/week_4_panadas.ipynb b/week_4_panadas.ipynb index 9080a02..045cd33 100644 --- a/week_4_panadas.ipynb +++ b/week_4_panadas.ipynb @@ -23,7 +23,7 @@ "metadata": {}, "outputs": [], "source": [ - "#As allways we import pandas and numpy\n", + "#As always we import pandas and numpy\n", "import pandas as pd\n", "import numpy as np" ] @@ -52,10 +52,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "0 6\n", + "1 7\n", + "2 8\n", + "3 9\n", + "dtype: int64" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = pd.Series([6,7,8,9])\n", + "x\n" + ] }, { "cell_type": "markdown", @@ -66,10 +84,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "d 7\n", + "dtype: int64" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = pd.Series([6,7,8,9], index = list(\"adbc\"))\n", + "x[[\"d\"]]" + ] }, { "cell_type": "markdown", @@ -85,10 +118,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "Ohio 35000\n", + "Texas 71000\n", + "Oregon 16000\n", + "Utah 5000\n", + "dtype: int64" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "states_dict = {\"Ohio\":35000, \"Texas\":71000, \"Oregon\":16000, \"Utah\":5000}\n", + "\n", + "states_series = pd.Series(states_dict)\n", + "states_series" + ] }, { "cell_type": "markdown", @@ -99,10 +152,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "OH 35000\n", + "TX 71000\n", + "OR 16000\n", + "UT 5000\n", + "dtype: int64" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "states_series.index = [\"OH\", \"TX\", \"OR\", \"UT\"]\n", + "\n", + "states_series" + ] }, { "cell_type": "markdown", @@ -125,9 +197,91 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stateyearpop
0Ohio20001.5
1Ohio20011.7
2Ohio20023.6
3Nevada20012.4
4Nevada20022.9
5Nevada20033.2
\n", + "
" + ], + "text/plain": [ + " state year pop\n", + "0 Ohio 2000 1.5\n", + "1 Ohio 2001 1.7\n", + "2 Ohio 2002 3.6\n", + "3 Nevada 2001 2.4\n", + "4 Nevada 2002 2.9\n", + "5 Nevada 2003 3.2" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "data = {\n", " 'state': ['Ohio', 'Ohio', 'Ohio', 'Nevada', 'Nevada', 'Nevada'],\n", @@ -148,10 +302,95 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stateyearpop
zeroOhio20001.5
oneOhio20011.7
twoOhio20023.6
threeNevada20012.4
fourNevada20022.9
fiveNevada20033.2
\n", + "
" + ], + "text/plain": [ + " state year pop\n", + "zero Ohio 2000 1.5\n", + "one Ohio 2001 1.7\n", + "two Ohio 2002 3.6\n", + "three Nevada 2001 2.4\n", + "four Nevada 2002 2.9\n", + "five Nevada 2003 3.2" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.index = [\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\"]\n", + "df" + ] }, { "cell_type": "markdown", @@ -162,10 +401,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "zero Ohio\n", + "one Ohio\n", + "two Ohio\n", + "three Nevada\n", + "four Nevada\n", + "five Nevada\n", + "Name: state, dtype: object \n", + "\n", + "zero Ohio\n", + "one Ohio\n", + "two Ohio\n", + "three Nevada\n", + "four Nevada\n", + "five Nevada\n", + "Name: state, dtype: object\n" + ] + } + ], + "source": [ + "print(df[\"state\"], \"\\n\")\n", + "print(df.state)\n" + ] }, { "cell_type": "markdown", @@ -176,10 +440,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "state Ohio\n", + "year 2000\n", + "pop 1.5\n", + "Name: zero, dtype: object \n", + "\n", + "state Ohio\n", + "year 2000\n", + "pop 1.5\n", + "Name: zero, dtype: object\n" + ] + } + ], + "source": [ + "print(df.loc[\"zero\"], \"\\n\")\n", + "print(df.iloc[0])" + ] }, { "cell_type": "markdown", @@ -190,10 +473,102 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stateyearpoprating
zeroOhio20001.55
oneOhio20011.74
twoOhio20023.63
threeNevada20012.42
fourNevada20022.91
fiveNevada20033.20
\n", + "
" + ], + "text/plain": [ + " state year pop rating\n", + "zero Ohio 2000 1.5 5\n", + "one Ohio 2001 1.7 4\n", + "two Ohio 2002 3.6 3\n", + "three Nevada 2001 2.4 2\n", + "four Nevada 2002 2.9 1\n", + "five Nevada 2003 3.2 0" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[\"rating\"] = [5,4,3,2,1,0]\n", + "df" + ] }, { "cell_type": "markdown", @@ -204,10 +579,109 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
stateyearpopratingnonsense
zeroOhio20001.557.5
oneOhio20011.746.8
twoOhio20023.6310.8
threeNevada20012.424.8
fourNevada20022.912.9
fiveNevada20033.200.0
\n", + "
" + ], + "text/plain": [ + " state year pop rating nonsense\n", + "zero Ohio 2000 1.5 5 7.5\n", + "one Ohio 2001 1.7 4 6.8\n", + "two Ohio 2002 3.6 3 10.8\n", + "three Nevada 2001 2.4 2 4.8\n", + "four Nevada 2002 2.9 1 2.9\n", + "five Nevada 2003 3.2 0 0.0" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df[\"nonsense\"] = df[\"rating\"] * df[\"pop\"]\n", + "df" + ] }, { "cell_type": "markdown", @@ -224,10 +698,94 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 11, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
abcde
series_numerical0.0000001.0000002.0000003.0000004.000000
series_zeros0.0000000.0000000.0000000.0000000.000000
series_random0.3870980.2426020.3049840.6079780.380149
\n", + "
" + ], + "text/plain": [ + " a b c d e\n", + "series_numerical 0.000000 1.000000 2.000000 3.000000 4.000000\n", + "series_zeros 0.000000 0.000000 0.000000 0.000000 0.000000\n", + "series_random 0.387098 0.242602 0.304984 0.607978 0.380149" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "idx = pd.Index(list(\"abcde\"))\n", + "series_numerical = pd.Series(np.arange(5), index = idx)\n", + "series_zeros = pd.Series(np.zeros(5), index = idx)\n", + "series_random = pd.Series(np.random.rand(5), index = idx)\n", + "\n", + "series_list = list([series_numerical, series_zeros, series_random])\n", + "series_index = pd.Index([\"series_numerical\", \"series_zeros\", \"series_random\"])\n", + "numeric_df = pd.DataFrame(series_list, index = series_index)\n", + "\n", + "numeric_df\n", + "\n", + "# I did consult chatgpt on this concerning the style I wrote with declaring the few extra variables (idx, series_list, series_index) and \n", + "# potential other ways to write it\n", + "\n" + ] }, { "cell_type": "markdown", @@ -238,10 +796,89 @@ }, { "cell_type": "code", - "execution_count": 30, + "execution_count": 12, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
numericalzerosrandom
a0.00.00.387098
b1.00.00.242602
c2.00.00.304984
d3.00.00.607978
e4.00.00.380149
\n", + "
" + ], + "text/plain": [ + " numerical zeros random\n", + "a 0.0 0.0 0.387098\n", + "b 1.0 0.0 0.242602\n", + "c 2.0 0.0 0.304984\n", + "d 3.0 0.0 0.607978\n", + "e 4.0 0.0 0.380149" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "transposed_numeric_df = numeric_df.T \n", + "transposed_numeric_df.columns = [\"numerical\", \"zeros\", \"random\"]\n", + "transposed_numeric_df" + ] }, { "cell_type": "markdown", @@ -252,10 +889,88 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
numericalzerosrandom
d3.00.00.607978
a0.00.00.387098
e4.00.00.380149
c2.00.00.304984
b1.00.00.242602
\n", + "
" + ], + "text/plain": [ + " numerical zeros random\n", + "d 3.0 0.0 0.607978\n", + "a 0.0 0.0 0.387098\n", + "e 4.0 0.0 0.380149\n", + "c 2.0 0.0 0.304984\n", + "b 1.0 0.0 0.242602" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "transposed_numeric_df_random_descending = transposed_numeric_df.sort_values(\"random\", ascending = False)\n", + "transposed_numeric_df_random_descending" + ] }, { "cell_type": "markdown", @@ -266,10 +981,67 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
numericalzerosrandom
d3.00.00.607978
e4.00.00.380149
\n", + "
" + ], + "text/plain": [ + " numerical zeros random\n", + "d 3.0 0.0 0.607978\n", + "e 4.0 0.0 0.380149" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "greater_than_2 = transposed_numeric_df.loc[transposed_numeric_df.numerical > 2]\n", + "greater_than_2" + ] }, { "cell_type": "markdown", @@ -280,10 +1052,88 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " numerical zeros random random5\n", + "a 0.0 0.0 0.387098 1.935491\n", + "b 1.0 0.0 0.242602 1.213010\n", + "c 2.0 0.0 0.304984 1.524922\n", + "d 3.0 0.0 0.607978 3.039889\n", + "e 4.0 0.0 0.380149 1.900745\n", + "-----------------------------------------------------------------\n", + "All rows where numerical is greater than random5:\n" + ] + }, + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
numericalzerosrandomrandom5
c2.00.00.3049841.524922
e4.00.00.3801491.900745
\n", + "
" + ], + "text/plain": [ + " numerical zeros random random5\n", + "c 2.0 0.0 0.304984 1.524922\n", + "e 4.0 0.0 0.380149 1.900745" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "transposed_numeric_df[\"random5\"] = transposed_numeric_df[\"random\"] * 5\n", + "greater_than_random_5 = transposed_numeric_df[transposed_numeric_df[\"numerical\"] > transposed_numeric_df[\"random5\"]]\n", + "print(transposed_numeric_df)\n", + "print(\"-----------------------------------------------------------------\")\n", + "print(\"All rows where numerical is greater than random5:\")\n", + "greater_than_random_5" + ] }, { "cell_type": "markdown", @@ -294,10 +1144,100 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
numericalzerosrandomrandom5even
a0.00.00.3870981.935491True
b1.00.00.2426021.213010False
c2.00.00.3049841.524922True
d3.00.00.6079783.039889False
e4.00.00.3801491.900745True
\n", + "
" + ], + "text/plain": [ + " numerical zeros random random5 even\n", + "a 0.0 0.0 0.387098 1.935491 True\n", + "b 1.0 0.0 0.242602 1.213010 False\n", + "c 2.0 0.0 0.304984 1.524922 True\n", + "d 3.0 0.0 0.607978 3.039889 False\n", + "e 4.0 0.0 0.380149 1.900745 True" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "transposed_numeric_df[\"even\"] = transposed_numeric_df[\"numerical\"] % 2 == 0\n", + "transposed_numeric_df" + ] }, { "cell_type": "markdown", @@ -308,10 +1248,121 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
numericalzerosrandomrandom5eveneven_odd
a0.00.00.3870981.935491Trueeven
b1.00.00.2426021.213010Falseodd
c2.00.00.3049841.524922Trueeven
d3.00.00.6079783.039889Falseodd
e4.00.00.3801491.900745Trueeven
\n", + "
" + ], + "text/plain": [ + " numerical zeros random random5 even even_odd\n", + "a 0.0 0.0 0.387098 1.935491 True even\n", + "b 1.0 0.0 0.242602 1.213010 False odd\n", + "c 2.0 0.0 0.304984 1.524922 True even\n", + "d 3.0 0.0 0.607978 3.039889 False odd\n", + "e 4.0 0.0 0.380149 1.900745 True even" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\" \n", + "I wrote this two ways. I find the one that I commented out with the lambda function \n", + "is cleaner with less code as you don't need to write the separate function. I used the \n", + "second one as that is how it was shown in the book. I found the lambda version on the \n", + "geeksforgeeks website, it's in the url below this line. \n", + "https://www.geeksforgeeks.org/python/ways-to-apply-an-if-condition-in-pandas-dataframe/\n", + "\"\"\";\n", + "\n", + "def ev_odd(x):\n", + " if x == True:\n", + " return \"even\"\n", + " else:\n", + " return \"odd\"\n", + "\n", + "# transposed_numeric_df[\"even_odd\"] = transposed_numeric_df[\"even\"].apply(lambda x: \"even\" if x == True else \"odd\")\n", + "transposed_numeric_df[\"even_odd\"] = transposed_numeric_df[\"even\"].apply(ev_odd)\n", + "transposed_numeric_df" + ] }, { "cell_type": "markdown", @@ -322,10 +1373,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "numerical 10.000000\n", + "zeros 0.000000\n", + "random 1.922811\n", + "random5 9.614057\n", + "even 3.000000\n", + "dtype: float64" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"\"\"\n", + "I purposely filtered out the even_odd column as calculating the sum just \n", + "creates a long string of evenoodevenoddeven. I left the even column in, \n", + "even though is just True/False as technically True == 1 and False == 0. So \n", + "you can technically add them. \n", + "\"\"\";\n", + "\n", + "columns = [\"numerical\", \"zeros\", \"random\", \"random5\", \"even\"]\n", + "\n", + "transposed_numeric_df[columns].sum(axis = 0)" + ] }, { "cell_type": "markdown", @@ -336,15 +1414,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "numerical e\n", + "zeros a\n", + "random d\n", + "random5 d\n", + "even a\n", + "dtype: object" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "transposed_numeric_df[columns].idxmax()\n", + "\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "base", + "display_name": "ml-env", "language": "python", "name": "python3" }, @@ -358,7 +1455,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.4" + "version": "3.10.18" } }, "nbformat": 4, diff --git a/week_5_vectors_applications.ipynb b/week_5_vectors_applications.ipynb index 11948c0..51ea02b 100644 --- a/week_5_vectors_applications.ipynb +++ b/week_5_vectors_applications.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -28,15 +28,15 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "queen = np.array([5, 6, 4])\n", "women = np.array([1, 3, 2])\n", "man = np.array([5, 5, 5])\n", - "royalty = None\n", - "king = None\n", + "royalty = queen - women\n", + "king = royalty + man\n", "\n" ] }, @@ -52,13 +52,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test passed for [5]\n", + "Test passed for [3.2 0.1]\n", + "Test passed for [-2 2 2]\n", + "Test passed for [70 2 28 36 36 7 34 99 33 82]\n" + ] + } + ], "source": [ + "\"\"\"\n", + "I wrote vector_magnitude two different ways, the commented version use \n", + "a for loop to sum the square of each element and then return the square \n", + "root of that sum. In the second version I compute everything in one line. \n", + "\"\"\"\n", + "\n", + "\n", + "# def vector_magnitude(np_vector: npt.NDArray) -> np.float64:\n", + "# sum = 0 \n", + "# for num in np_vector:\n", + "# sum += num**2 \n", + "\n", + "# return sum**0.5\n", + "\n", "def vector_magnitude(np_vector: npt.NDArray) -> np.float64:\n", - " #Write your code here\n", - " return \n", + " return sum((np_vector**2))**0.5\n", "\n", "def test_vector_magnitude(np_vector: npt.NDArray) -> None:\n", " if vector_magnitude(np_vector) == np.linalg.norm(np_vector):\n", @@ -75,7 +99,7 @@ "test_vector_magnitude(d1_vector)\n", "test_vector_magnitude(d2_vector)\n", "test_vector_magnitude(d3_vector)\n", - "test_vector_magnitude(d10_vector)" + "test_vector_magnitude(d10_vector)\n" ] }, { @@ -90,15 +114,37 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test passed for [1.]\n", + "Test passed for [0.99951208 0.03123475]\n", + "Test passed for [-0.57735027 0.57735027 0.57735027]\n" + ] + } + ], "source": [ "d1_unit_vector = np.array([1.])\n", "d2_unit_vector = np.array([0.99951208, 0.03123475])\n", "d3_unit_vector = np.array([-0.57735027, 0.57735027, 0.57735027])\n", "\n", - "#Impliment vector_magnitude and test_vector_magnitude here" + "#Impliment vector_magnitude and test_vector_magnitude here\n", + "def create_unit_vector(arr):\n", + " return arr * (1 / vector_magnitude(arr))\n", + "\n", + "def test_create_unit_vector(arr, test_arr):\n", + " if np.allclose(create_unit_vector(arr), test_arr):\n", + " print(f\"Test passed for {test_arr}\")\n", + " else:\n", + " print(f\"Test failed for {test_arr}\")\n", + "\n", + "test_create_unit_vector(create_unit_vector(d1_vector), d1_unit_vector)\n", + "test_create_unit_vector(create_unit_vector(d2_vector), d2_unit_vector)\n", + "test_create_unit_vector(create_unit_vector(d3_vector), d3_unit_vector)" ] }, { @@ -115,10 +161,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test passed for [5 6 7] and [5 6 7]\n", + "Test passed for [2 3 4] and [7. 8. 9.]\n", + "Test passed for [0.0001 0.0002 0.0003] and [100000 200000 300000]\n" + ] + } + ], + "source": [ + "vector1 = np.array([5,6,7])\n", + "vector2_1 = np.array([2,3,4])\n", + "vector2_2 = np.array([7.0, 8.0, 9.0])\n", + "vector3_1 = np.array([0.0001, 0.0002, 0.0003])\n", + "vector3_2 = np.array([100_000, 200_000, 300_000])\n", + "\n", + "def my_dot(arr1, arr2):\n", + " return sum(arr1 * arr2)\n", + "\n", + "def test_my_dot(arr1, arr2):\n", + " if my_dot(arr1, arr2) == np.dot(arr1, arr2):\n", + " print(f\"Test passed for {arr1} and {arr2}\")\n", + " else:\n", + " print(f\"Test failed\")\n", + "\n", + "test_my_dot(vector1, vector1)\n", + "test_my_dot(vector2_1, vector2_2)\n", + "test_my_dot(vector3_1, vector3_2)" + ] }, { "cell_type": "markdown", @@ -138,15 +213,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cat 1 prediction: 21.15\n", + "Cat 1 prediction error == 3.06\n", + "\n", + "\n", + "Cat 2 prediction: 15.21\n", + "Cat 2 prediction error == 1.38\n", + "\n" + ] + } + ], "source": [ "cat_1_array = np.array([28.57, 10.435])\n", "cat_1_actual_weight = 24.21\n", "\n", "cat_2_array = np.array([19.04, 6.93])\n", - "cat_2_actual_weight = 13.831" + "cat_2_actual_weight = 13.831\n", + "\n", + "def predict_weight(arr):\n", + " return 0.23 * arr[0] + 1.07 * arr[1] + 3.412\n", + "\n", + "def prediction_error(arr, actual_weight):\n", + " return abs(predict_weight(arr) - actual_weight)\n", + "\n", + "print(f\"Cat 1 prediction: {predict_weight(cat_1_array):.2f}\")\n", + "print(f\"Cat 1 prediction error == {prediction_error(cat_1_array, cat_1_actual_weight):.2f}\\n\")\n", + "print(\"\")\n", + "print(f\"Cat 2 prediction: {predict_weight(cat_2_array):.2f}\")\n", + "print(f\"Cat 2 prediction error == {prediction_error(cat_2_array, cat_2_actual_weight):.2f}\\n\")\n" ] }, { @@ -182,10 +283,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loop version is faster!\n" + ] + } + ], + "source": [ + "import time\n", + "\n", + "def linear_comb_loop(scalars_arr, vectors_arr):\n", + " curr = np.array(np.zeros(3))\n", + "\n", + " for i in range(len(vectors_arr)):\n", + " curr += scalars_arr[i] * vectors_arr[i]\n", + "\n", + " return curr\n", + "\n", + "scalars_array = np.array([1, 2, -3])\n", + "vectors_array = np.array([[4,5,1], [-4,0,-4], [1,3,2]])\n", + "\n", + "def linear_comb_vectorized(scalars_arr, vectors_arr):\n", + " return np.dot(scalars_arr, vectors_arr)\n", + "\n", + "def linear_comb_speed_test(scalars_arr, vectors_arr):\n", + " start1 = time.time()\n", + " linear_comb_loop(scalars_arr, vectors_arr)\n", + " end1 = time.time() - start1\n", + "\n", + " start2 = time.time()\n", + " linear_comb_vectorized(scalars_arr, vectors_arr)\n", + " end2 = time.time() - start2\n", + "\n", + " if(end1 > end2):\n", + " print(\"Loop version is faster!\")\n", + " else:\n", + " print(\"Vectorized version is faster!\")\n", + "\n", + "linear_comb_speed_test(scalars_array, vectors_array)\n", + "\n" + ] }, { "cell_type": "markdown", @@ -198,22 +340,47 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "basis_vector = np.array([1,3])\n", + "rand_dist = np.random.uniform(-4, 4, 100)\n", + "\n", + "\"\"\"\n", + "this is how I originally completed the problem\n", + "\n", + "sub_space = np.zeros((100, 2))\n", + "for i in range(len(rand_dist)):\n", + " sub_space[i] = rand_dist[i] * basis_vector\n", + "\"\"\"\n", + "sub_space = rand_dist[:, None] * basis_vector" + ] }, { "cell_type": "code", - "execution_count": 101, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAioAAAGdCAYAAAA8F1jjAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjUsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvWftoOwAAAAlwSFlzAAAPYQAAD2EBqD+naQAAMwtJREFUeJzt3X90VPWd//HXJCQZEpOBRMKEFSH8UBuDQLTBiLaCoaI09UfXnmqxaLtUKOwq7LaCFUOqGNbuqquw6NeegpVa7NkWkZbNCmirYjBqRAlZW6GhoExAyTITg0lk5n7/SCclZJLMTGbm3pl5Ps6ZP2bm3uQ9B2Fefn68PzbDMAwBAABYUIrZBQAAAPSFoAIAACyLoAIAACyLoAIAACyLoAIAACyLoAIAACyLoAIAACyLoAIAACxriNkFDJbP59ORI0eUnZ0tm81mdjkAACAIhmGotbVVo0aNUkpK3+MmcR9Ujhw5otGjR5tdBgAACMPhw4d1zjnn9Pl+3AeV7OxsSV0fNCcnx+RqAABAMDwej0aPHt39Pd6Xu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ee2+P5WWedJUkaP368zjnnHDNKirg33nhDb775pi6//HINHz5cBw4c0IoVKzR+/HjLj6aE4qOPPtKVV16pMWPG6N/+7d/08ccfd7/ndDpNrCyyDh06pJaWFh06dEher7e758+ECRO6//uNN0uXLtW8efN0ySWXqLS0VI8++qja2tp0++23m11axHz66afav39/9/Ompibt2bNHubm5vf4dileLFi3Ss88+qy1btig7O7t7jZHD4dDQoUNNri4yli9frmuuuUbnnnuuWltb9eyzz+r3v/+9/ud//sfs0iImOzu717oi//rGqK83ivq+ogTQ1NSUcNuT33vvPWPGjBlGbm6ukZGRYYwdO9ZYsGCB8eGHH5pdWkStX7/ekBTwkUjmzZsX8DO+/PLLZpc2KI8//rhx7rnnGunp6UZpaamxe/dus0uKqJdffjngn9u8efPMLi1i+vr7t379erNLi5jvfOc7xpgxY4z09HRjxIgRxlVXXWW8+OKLZpcVdbHanpxUa1QAAEB8iY/JegAAkJQIKgAAwLIIKgAAwLIIKgAAwLIIKgAAwLIIKgAAwLIIKgAAwLIIKgAAwLIIKgAAwLIIKgAAwLIIKgAAwLIIKgAAwLL+P0p/NOgLXd0eAAAAAElFTkSuQmCC", + "text/plain": [ + "
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "import matplotlib.pyplot as plt\n", "\n", "def plot_vectors(vectors):\n", " plt.scatter(*zip(*vectors))\n", - " plt.show()" + " plt.show()\n", + "\n", + "plot_vectors(sub_space)" ] }, { @@ -259,13 +426,98 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Non mean-centered vector tests: \n", + "Pearson function passed.\n", + "Cosine test passed.\n", + "My functions pearson and cosine functions are NOT equal to each other.\n", + "------------------------------------------------\n", + "Mean-centered vector tests: \n", + "Pearson function passed.\n", + "Cosine test passed.\n", + "My functions pearson and cosine functions are NOT equal to each other.\n" + ] + } + ], + "source": [ + "from scipy.spatial.distance import cosine\n", + "\n", + "# non-mean centered vectors\n", + "coeff_arr1 = np.array([2,3,4])\n", + "coeff_arr2 = np.array([5,6,7])\n", + "\n", + "# mean centered vectors\n", + "arr1_mean_centered = coeff_arr1 - coeff_arr1.mean()\n", + "arr2_mean_centered = coeff_arr2 - coeff_arr2.mean()\n", + "\n", + "def pearson_corr(x_arr, y_arr):\n", + " x_mean = x_arr - np.mean(x_arr)\n", + " y_mean = y_arr - np.mean(y_arr)\n", + " numerator = np.sum((x_mean) * (y_mean)) \n", + " denominator = np.sqrt((np.sum((x_mean)**2)) * (np.sum((y_mean)**2)))\n", + " return numerator / denominator\n", + "\n", + "def cosine_simil(x_arr, y_arr):\n", + " numerator = np.dot(x_arr, y_arr)\n", + " denominator = np.linalg.norm(x_arr) * np.linalg.norm(y_arr)\n", + " return numerator / denominator\n", + "\n", + "def test_pearson(arr1, arr2):\n", + " if (pearson_corr(arr1, arr2)) == (np.corrcoef(arr1, arr2)[0,1]):\n", + " print(\"Pearson function passed.\")\n", + " else:\n", + " print(\"Pearson function failed.\")\n", + "\n", + "def test_cosine(arr1, arr2):\n", + " if np.isclose((cosine_simil(arr1, arr2)), (1 - cosine(arr1, arr2))):\n", + " print(\"Cosine test passed.\")\n", + " else:\n", + " print(\"Cosine test failed.\")\n", + "\n", + "def test_person_cosine_equality(arr1, arr2):\n", + " # if (np.isclose((pearson_corr(arr1, arr2)), (cosine_simil(arr1, arr2)))):\n", + " if pearson_corr(arr1, arr2) == cosine_simil(arr1, arr2):\n", + " print(\"Both of my functions are equal to each other.\")\n", + " else:\n", + " print(\"My functions pearson and cosine functions are NOT equal to each other.\")\n", + "\n", + "\n", + "print(\"Non mean-centered vector tests: \")\n", + "test_pearson(coeff_arr1, coeff_arr2)\n", + "test_cosine(coeff_arr1, coeff_arr2)\n", + "test_person_cosine_equality(coeff_arr1, coeff_arr2)\n", + "\n", + "print(\"------------------------------------------------\")\n", + "print(\"Mean-centered vector tests: \")\n", + "test_pearson(arr1_mean_centered, arr2_mean_centered)\n", + "test_cosine(arr1_mean_centered, arr2_mean_centered)\n", + "test_person_cosine_equality(arr1_mean_centered, arr2_mean_centered)\n", + "\n", + "\n", + "\"\"\"\n", + "I used np.isclose() in the cosine test because they are comparing two floating point \n", + "numbers. Since computers have issues with floating point numbers (especiallly in equality \n", + "comparison), I chose to use the isclose() numpy function since that is testing if they \n", + "are close, which they are. By doing this, my cosine tests passed for both non-mean and \n", + "mean centered vectors. \n", + "\n", + "For the test_person_cosine_equality is is printing that they are not equal as expected. \n", + "In the book it states that these two functions can give different results for the same data \n", + "because the functions start from different assumptions.\n", + "\"\"\";\n", + "\n", + "\n", + "\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "AD_450_env", + "display_name": "ml-env", "language": "python", "name": "python3" }, @@ -279,7 +531,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.16" + "version": "3.10.18" } }, "nbformat": 4,