diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index fdaead28..6aef842b 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -72,31 +72,91 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "id": "n0m48JsS-nMC" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0,0,2,0,3,4,5,7,6,7,8,4,4,6,9,5,10,12,16,8,19,17,16,16,12,12,12,9,8,4,2,8,3,5,6,3,2,2,0,0\n", + "0,1,0,2,2,4,2,4,2,8,7,8,5,6,12,3,13,14,18,4,10,17,14,11,9,15,3,10,3,8,10,7,6,3,6,1,1,3,0,0\n", + "0,0,1,0,2,2,2,5,5,7,7,6,8,5,7,13,14,11,15,16,6,14,11,10,9,5,4,7,8,7,4,7,2,1,5,2,3,2,0,1\n", + "0,0,0,2,4,2,2,2,4,4,5,8,5,9,8,13,8,9,11,15,7,8,18,14,16,3,6,7,9,6,8,7,2,3,2,2,1,2,0,1\n", + "0,1,2,1,3,2,5,7,3,8,3,6,5,5,3,15,16,6,15,6,18,13,4,10,5,5,12,3,7,7,3,3,4,6,6,1,1,0,2,0\n", + "0,0,1,2,3,1,1,7,8,2,2,6,8,12,12,14,6,5,18,12,13,6,17,8,14,3,4,7,7,4,5,7,4,5,2,2,4,0,2,1\n", + "0,1,0,0,4,3,1,3,8,6,9,3,10,6,3,14,7,15,18,6,7,4,10,5,9,12,4,6,8,5,10,9,4,7,1,5,1,3,1,0\n", + "0,1,0,3,2,1,4,6,5,6,3,9,11,13,11,15,16,13,18,7,9,6,15,10,16,5,7,10,9,9,3,4,7,2,4,2,4,0,2,1\n", + "0,0,1,3,1,4,6,5,5,8,7,8,4,13,6,14,16,16,11,8,16,11,8,8,16,8,6,4,11,5,6,8,7,3,5,4,2,3,0,1\n", + "0,0,0,2,3,3,5,2,3,3,4,2,8,10,5,13,7,4,15,9,11,5,12,4,11,7,4,6,6,3,4,3,8,2,1,5,4,1,2,0\n", + "0,1,2,3,3,5,5,3,2,6,10,9,6,6,10,3,11,4,7,7,20,5,9,8,9,4,6,4,6,8,8,2,5,1,2,1,3,2,2,0\n", + "0,1,1,3,1,1,4,3,5,4,3,6,9,13,10,10,12,14,14,12,5,14,10,9,10,10,11,4,10,6,4,9,2,6,4,2,2,3,2,0\n", + "0,0,1,1,2,3,3,4,7,7,7,9,9,13,12,8,10,15,18,9,11,7,5,13,13,9,4,10,4,8,6,5,7,1,6,2,4,3,2,1\n", + "0,1,0,3,1,3,1,2,3,8,5,5,4,4,6,5,10,7,7,19,15,5,11,6,11,11,7,8,5,8,6,4,6,6,4,1,1,2,1,1\n", + "0,1,1,2,4,3,4,1,6,7,6,2,10,12,9,8,8,14,18,15,16,15,16,9,10,12,14,12,8,5,4,5,2,7,5,1,4,3,1,0\n", + "0,0,2,1,4,1,5,4,5,6,10,11,3,5,13,11,4,8,13,11,6,10,12,5,16,4,9,5,3,4,7,4,6,7,5,2,3,2,2,0\n", + "0,1,2,1,4,4,4,3,2,9,7,2,9,3,11,12,14,8,18,9,8,13,4,12,14,3,10,12,8,8,10,8,6,2,6,3,1,1,2,0\n", + "0,0,1,2,3,4,6,7,2,3,6,5,12,13,4,12,8,14,13,18,7,18,9,9,15,7,12,11,4,7,10,7,2,3,2,5,4,0,1,0\n", + "0,1,1,1,1,3,1,4,8,3,3,10,6,10,9,5,11,10,6,9,19,4,18,7,10,15,3,3,10,9,10,3,6,1,1,2,3,2,1,0\n", + "0,1,0,3,4,5,5,3,6,2,8,4,10,8,12,12,11,4,18,6,19,5,7,14,14,5,8,4,10,6,3,8,7,1,6,5,3,2,0,1\n", + "0,1,0,1,4,1,1,5,5,3,4,3,11,6,11,11,6,12,13,10,16,5,15,15,12,5,13,5,8,6,9,7,3,3,3,1,4,2,1,1\n", + "0,0,2,1,4,2,1,4,4,5,6,11,7,10,8,7,16,11,16,11,9,7,6,17,9,3,4,6,9,11,7,5,8,6,4,2,1,3,2,1\n", + "0,0,0,0,2,5,5,1,6,2,8,3,8,13,10,7,7,6,4,9,7,8,17,15,8,14,4,12,5,3,9,7,7,6,3,5,2,3,0,1\n", + "0,0,0,1,4,4,3,7,8,8,10,11,10,11,7,4,13,8,12,13,12,17,7,16,7,8,4,10,5,7,9,2,7,7,3,1,3,1,0,0\n", + "0,0,1,2,1,5,4,7,2,4,9,10,4,4,10,11,5,8,11,6,8,17,5,15,12,11,8,8,5,5,3,5,4,5,1,4,4,1,1,0\n", + "0,0,2,2,1,4,6,5,8,5,6,9,7,7,10,5,14,7,7,13,6,11,7,11,8,12,10,5,4,5,10,5,3,1,1,2,1,3,2,1\n", + "0,0,2,0,3,1,4,3,7,8,3,11,3,10,9,9,7,5,7,10,9,7,6,7,7,4,11,6,5,7,3,5,3,4,2,2,2,1,1,0\n", + "0,0,2,3,3,3,1,5,3,2,4,11,9,11,14,5,11,14,6,18,14,7,10,13,10,15,13,10,12,5,3,5,6,3,5,2,3,2,0,0\n", + "0,0,2,1,2,3,5,5,6,7,5,4,12,9,5,14,6,14,7,4,7,17,9,9,12,14,6,13,4,3,6,9,8,7,3,1,1,2,1,1\n", + "0,0,0,3,2,3,1,4,8,8,2,2,8,3,5,8,7,4,16,11,18,12,8,9,7,10,12,8,8,7,9,8,5,2,1,5,4,2,1,0\n", + "0,0,0,0,3,4,6,6,8,5,2,9,8,8,11,8,10,12,8,13,9,5,5,17,13,9,3,5,11,4,4,2,4,5,5,2,4,1,1,0\n", + "0,1,2,2,2,1,5,7,2,6,10,4,7,8,4,9,5,15,12,11,13,9,7,16,6,7,13,4,3,6,5,3,3,5,2,3,4,1,0,1\n", + "0,0,1,3,1,5,1,7,5,5,2,7,6,11,10,8,13,16,6,7,11,4,11,14,13,7,6,4,3,10,4,8,2,7,4,4,2,1,1,0\n", + "0,1,1,3,3,1,3,6,2,8,5,6,12,4,4,13,15,17,12,11,6,11,4,7,11,8,13,6,4,9,8,6,2,1,6,1,1,1,2,0\n", + "0,1,0,0,3,3,4,6,2,8,4,9,6,4,8,14,15,16,7,18,6,8,13,7,6,7,9,6,4,7,10,3,7,7,6,4,1,1,1,0\n", + "0,1,1,0,2,5,6,3,8,2,9,9,4,4,9,9,13,14,10,17,10,19,11,12,5,13,7,5,6,5,3,4,4,1,5,2,3,1,1,1\n", + "0,1,1,2,2,1,2,2,8,4,8,10,10,13,7,9,12,5,10,10,17,14,9,12,7,15,11,9,4,11,7,2,5,6,6,4,2,0,1,1\n", + "0,1,1,2,4,1,6,6,7,9,6,2,3,7,14,3,12,14,17,9,17,5,7,15,11,4,8,11,8,7,8,3,6,3,6,2,2,0,2,0\n", + "0,0,0,2,4,5,6,1,6,8,5,9,12,9,12,9,15,4,14,4,18,13,11,8,12,14,11,10,3,7,10,6,2,3,6,4,1,2,2,0\n", + "0,0,0,3,4,5,6,5,5,9,6,3,9,12,14,13,16,14,18,9,6,15,7,10,6,5,7,7,10,11,10,2,6,6,2,2,1,3,1,1\n", + "0,0,1,1,1,5,4,3,5,9,8,10,9,13,5,4,14,7,10,14,20,7,7,12,14,8,12,5,7,8,10,5,7,4,2,4,4,2,0,0\n", + "0,0,1,0,1,2,1,4,6,6,10,5,6,13,4,9,7,10,5,10,18,14,16,10,7,8,11,8,3,2,3,9,4,7,3,2,2,0,2,0\n", + "0,1,1,2,1,1,3,7,2,8,10,10,7,9,10,5,13,4,12,17,5,5,16,16,15,9,7,3,10,10,2,9,3,4,1,4,1,0,0,0\n", + "0,1,0,3,1,3,6,1,2,5,2,11,6,10,8,5,6,8,17,14,16,4,15,13,16,5,5,8,10,7,5,6,6,6,5,2,4,0,0,0\n", + "0,0,2,0,4,5,6,5,6,4,3,6,11,6,11,13,13,4,5,4,9,15,7,5,5,7,12,5,8,3,3,6,4,5,5,2,3,3,0,0\n", + "0,1,2,2,4,1,4,2,6,8,8,3,8,13,6,8,16,11,18,16,11,11,12,6,9,6,12,4,11,6,10,4,5,3,4,5,2,0,1,0\n", + "0,1,0,3,2,4,2,6,5,7,4,3,8,4,8,3,7,7,11,13,7,7,10,17,5,4,6,7,6,3,8,8,8,2,5,3,2,1,2,0\n", + "0,0,0,0,2,1,5,3,3,7,8,9,5,7,8,4,11,9,12,18,6,7,11,16,10,3,6,6,12,5,3,4,2,4,4,5,2,2,1,1\n", + "0,0,1,2,4,3,6,5,4,6,8,7,9,9,13,11,14,7,5,11,9,14,16,11,12,13,7,3,7,10,3,6,4,2,4,4,3,1,1,1\n", + "0,0,2,3,1,2,4,2,3,3,3,10,5,13,7,9,15,13,6,17,14,4,12,10,12,8,13,11,10,3,7,4,2,7,5,5,3,1,0,0\n", + "0,1,0,0,2,1,2,3,3,7,2,9,9,6,12,14,15,13,18,17,14,10,8,14,4,6,3,8,3,11,9,4,2,6,5,3,1,3,0,0\n", + "0,0,1,2,2,2,6,2,3,2,4,8,10,7,6,11,6,17,4,17,12,15,17,11,4,9,9,13,3,7,5,2,5,4,6,2,2,0,1,0\n", + "0,0,2,3,4,2,6,3,4,3,4,7,10,11,11,14,16,6,6,17,7,12,17,7,9,7,10,4,3,8,9,9,6,6,6,4,1,0,1,1\n", + "0,0,1,2,1,5,4,3,8,2,10,11,9,7,8,4,15,7,13,9,12,9,15,13,9,11,11,4,9,5,5,7,3,6,6,2,3,1,1,0\n", + "0,1,1,0,3,2,2,7,2,5,7,9,12,4,5,9,16,11,9,15,18,5,10,13,7,11,3,13,6,11,2,8,7,7,4,4,3,2,0,1\n", + "0,1,0,1,2,2,4,3,6,5,2,4,10,3,8,7,11,10,9,12,11,16,12,14,9,3,10,12,5,2,5,8,7,6,4,1,4,3,2,1\n", + "0,1,0,3,3,1,3,2,3,2,10,5,6,4,3,11,8,7,14,12,7,14,8,9,14,14,3,11,8,9,5,3,6,3,1,3,3,2,2,0\n", + "0,0,2,2,4,3,1,3,4,4,7,3,10,9,11,8,5,8,14,16,16,18,9,12,14,3,9,11,7,8,2,3,7,4,3,4,3,2,2,0\n", + "0,1,0,2,4,1,4,3,6,8,7,7,6,7,6,14,9,7,4,18,13,14,18,4,7,6,10,9,12,10,10,9,6,5,2,3,2,1,0,1\n", + "0,0,1,1,4,3,5,1,3,6,6,6,12,5,7,12,16,14,10,10,9,10,9,8,9,9,6,12,12,2,5,4,8,5,6,5,1,3,2,0\n" + ] + } + ], "source": [ "all_paths = [\n", - " \"../../05_src/data/assignment_2_data/inflammation_01.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_02.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_03.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_04.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_05.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_06.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_07.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_08.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_09.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_10.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_11.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_12.csv\"\n", + " \"../../05_src/data/assignment_2_data/inflammation_06.csv\"\n", "]\n", "\n", "with open(all_paths[0], 'r') as f:\n", " # YOUR CODE HERE: Use the readline() or readlines() method to read the .csv file into a variable\n", - " \n", - " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection" + " lines = f.readlines()\n", + "\n", + " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection\n", + " for line in lines:\n", + " print(line.strip())\n", + " " ] }, { @@ -130,7 +190,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "id": "82-bk4CBB1w4" }, @@ -145,12 +205,15 @@ " # Implement the specific operation based on the 'operation' argument\n", " if operation == 'mean':\n", " # YOUR CODE HERE: Calculate the mean (average) number of flare-ups for each patient\n", + " summary_values = np.mean(data, axis=ax)\n", "\n", " elif operation == 'max':\n", " # YOUR CODE HERE: Calculate the maximum number of flare-ups experienced by each patient\n", + " summary_values = np.max(data, axis=ax)\n", "\n", " elif operation == 'min':\n", " # YOUR CODE HERE: Calculate the minimum number of flare-ups experienced by each patient\n", + " summary_values = np.min(data, axis=ax)\n", "\n", " else:\n", " # If the operation is not one of the expected values, raise an error\n", @@ -161,11 +224,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "id": "3TYo0-1SDLrd" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "60\n" + ] + } + ], "source": [ "# Test it out on the data file we read in and make sure the size is what we expect i.e., 60\n", "# Your output for the first file should be 60\n", @@ -228,7 +299,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": { "id": "_svDiRkdIwiT" }, @@ -251,7 +322,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": { "id": "LEYPM5v4JT0i" }, @@ -261,15 +332,27 @@ "\n", "def detect_problems(file_path):\n", " #YOUR CODE HERE: Use patient_summary() to get the means and check_zeros() to check for zeros in the means\n", + " means = patient_summary(file_path, 'mean')\n", + " has_zeros = check_zeros(means)\n", + " if has_zeros:\n", + " print(\"Warning: At least one patient has a mean inflammation of zero.\")\n", "\n", - " return" + " return has_zeros" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], "source": [ "# Test out your code here\n", "# Your output for the first file should be False\n", @@ -314,7 +397,8 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3", + "display_name": "python-env", + "language": "python", "name": "python3" }, "language_info": { @@ -327,7 +411,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.14" } }, "nbformat": 4,