diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index b98c21c65..188449b96 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -72,31 +72,307 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 391, "metadata": { "id": "n0m48JsS-nMC" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0,0,1,3,1,2,4,7,8,3,3,3,10,5,7,4,7,7,12,18,6,13,11,11,7,7,4,6,8,8,4,4,5,7,3,4,2,3,0,0\n", + "\n", + "0,1,2,1,2,1,3,2,2,6,10,11,5,9,4,4,7,16,8,6,18,4,12,5,12,7,11,5,11,3,3,5,4,4,5,5,1,1,0,1\n", + "\n", + "0,1,1,3,3,2,6,2,5,9,5,7,4,5,4,15,5,11,9,10,19,14,12,17,7,12,11,7,4,2,10,5,4,2,2,3,2,2,1,1\n", + "\n", + "0,0,2,0,4,2,2,1,6,7,10,7,9,13,8,8,15,10,10,7,17,4,4,7,6,15,6,4,9,11,3,5,6,3,3,4,2,3,2,1\n", + "\n", + "0,1,1,3,3,1,3,5,2,4,4,7,6,5,3,10,8,10,6,17,9,14,9,7,13,9,12,6,7,7,9,6,3,2,2,4,2,0,1,1\n", + "\n", + "0,0,1,2,2,4,2,1,6,4,7,6,6,9,9,15,4,16,18,12,12,5,18,9,5,3,10,3,12,7,8,4,7,3,5,4,4,3,2,1\n", + "\n", + "0,0,2,2,4,2,2,5,5,8,6,5,11,9,4,13,5,12,10,6,9,17,15,8,9,3,13,7,8,2,8,8,4,2,3,5,4,1,1,1\n", + "\n", + "0,0,1,2,3,1,2,3,5,3,7,8,8,5,10,9,15,11,18,19,20,8,5,13,15,10,6,10,6,7,4,9,3,5,2,5,3,2,2,1\n", + "\n", + "0,0,0,3,1,5,6,5,5,8,2,4,11,12,10,11,9,10,17,11,6,16,12,6,8,14,6,13,10,11,4,6,4,7,6,3,2,1,0,0\n", + "\n", + "0,1,1,2,1,3,5,3,5,8,6,8,12,5,13,6,13,8,16,8,18,15,16,14,12,7,3,8,9,11,2,5,4,5,1,4,1,2,0,0\n", + "\n", + "0,1,0,0,4,3,3,5,5,4,5,8,7,10,13,3,7,13,15,18,8,15,15,16,11,14,12,4,10,10,4,3,4,5,5,3,3,2,2,1\n", + "\n", + "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", + "\n", + "0,0,2,1,4,3,6,4,6,7,9,9,3,11,6,12,4,17,13,15,13,12,8,7,4,7,12,9,5,6,5,4,7,3,5,4,2,3,0,1\n", + "\n", + "0,0,0,0,1,3,1,6,6,5,5,6,3,6,13,3,10,13,9,16,15,9,11,4,6,4,11,11,12,3,5,8,7,4,6,4,1,3,0,0\n", + "\n", + "0,1,2,1,1,1,4,1,5,2,3,3,10,7,13,5,7,17,6,9,12,13,10,4,12,4,6,7,6,10,8,2,5,1,3,4,2,0,2,0\n", + "\n", + "0,1,1,0,1,2,4,3,6,4,7,5,5,7,5,10,7,8,18,17,9,8,12,11,11,11,14,6,11,2,10,9,5,6,5,3,4,2,2,0\n", + "\n", + "0,0,0,0,2,3,6,5,7,4,3,2,10,7,9,11,12,5,12,9,13,19,14,17,5,13,8,11,5,10,9,8,7,5,3,1,4,0,2,1\n", + "\n", + "0,0,0,1,2,1,4,3,6,7,4,2,12,6,12,4,14,7,8,14,13,19,6,9,12,6,4,13,6,7,2,3,6,5,4,2,3,0,1,0\n", + "\n", + "0,0,2,1,2,5,4,2,7,8,4,7,11,9,8,11,15,17,11,12,7,12,7,6,7,4,13,5,7,6,6,9,2,1,1,2,2,0,1,0\n", + "\n", + "0,1,2,0,1,4,3,2,2,7,3,3,12,13,11,13,6,5,9,16,9,19,16,11,8,9,14,12,11,9,6,6,6,1,1,2,4,3,1,1\n", + "\n", + "0,1,1,3,1,4,4,1,8,2,2,3,12,12,10,15,13,6,5,5,18,19,9,6,11,12,7,6,3,6,3,2,4,3,1,5,4,2,2,0\n", + "\n", + "0,0,2,3,2,3,2,6,3,8,7,4,6,6,9,5,12,12,8,5,12,10,16,7,14,12,5,4,6,9,8,5,6,6,1,4,3,0,2,0\n", + "\n", + "0,0,0,3,4,5,1,7,7,8,2,5,12,4,10,14,5,5,17,13,16,15,13,6,12,9,10,3,3,7,4,4,8,2,6,5,1,0,1,0\n", + "\n", + "0,1,1,1,1,3,3,2,6,3,9,7,8,8,4,13,7,14,11,15,14,13,5,13,7,14,9,10,5,11,5,3,5,1,1,4,4,1,2,0\n", + "\n", + "0,1,1,1,2,3,5,3,6,3,7,10,3,8,12,4,12,9,15,5,17,16,5,10,10,15,7,5,3,11,5,5,6,1,1,1,1,0,2,1\n", + "\n", + "0,0,2,1,3,3,2,7,4,4,3,8,12,9,12,9,5,16,8,17,7,11,14,7,13,11,7,12,12,7,8,5,7,2,2,4,1,1,1,0\n", + "\n", + "0,0,1,2,4,2,2,3,5,7,10,5,5,12,3,13,4,13,7,15,9,12,18,14,16,12,3,11,3,2,7,4,8,2,2,1,3,0,1,1\n", + "\n", + "0,0,1,1,1,5,1,5,2,2,4,10,4,8,14,6,15,6,12,15,15,13,7,17,4,5,11,4,8,7,9,4,5,3,2,5,4,3,2,1\n", + "\n", + "0,0,2,2,3,4,6,3,7,6,4,5,8,4,7,7,6,11,12,19,20,18,9,5,4,7,14,8,4,3,7,7,8,3,5,4,1,3,1,0\n", + "\n", + "0,0,0,1,4,4,6,3,8,6,4,10,12,3,3,6,8,7,17,16,14,15,17,4,14,13,4,4,12,11,6,9,5,5,2,5,2,1,0,1\n", + "\n", + "0,1,1,0,3,2,4,6,8,6,2,3,11,3,14,14,12,8,8,16,13,7,6,9,15,7,6,4,10,8,10,4,2,6,5,5,2,3,2,1\n", + "\n", + "0,0,2,3,3,4,5,3,6,7,10,5,10,13,14,3,8,10,9,9,19,15,15,6,8,8,11,5,5,7,3,6,6,4,5,2,2,3,0,0\n", + "\n", + "0,1,2,2,2,3,6,6,6,7,6,3,11,12,13,15,15,10,14,11,11,8,6,12,10,5,12,7,7,11,5,8,5,2,5,5,2,0,2,1\n", + "\n", + "0,0,2,1,3,5,6,7,5,8,9,3,12,10,12,4,12,9,13,10,10,6,10,11,4,15,13,7,3,4,2,9,7,2,4,2,1,2,1,1\n", + "\n", + "0,0,1,2,4,1,5,5,2,3,4,8,8,12,5,15,9,17,7,19,14,18,12,17,14,4,13,13,8,11,5,6,6,2,3,5,2,1,1,1\n", + "\n", + "0,0,0,3,1,3,6,4,3,4,8,3,4,8,3,11,5,7,10,5,15,9,16,17,16,3,8,9,8,3,3,9,5,1,6,5,4,2,2,0\n", + "\n", + "0,1,2,2,2,5,5,1,4,6,3,6,5,9,6,7,4,7,16,7,16,13,9,16,12,6,7,9,10,3,6,4,5,4,6,3,4,3,2,1\n", + "\n", + "0,1,1,2,3,1,5,1,2,2,5,7,6,6,5,10,6,7,17,13,15,16,17,14,4,4,10,10,10,11,9,9,5,4,4,2,1,0,1,0\n", + "\n", + "0,1,0,3,2,4,1,1,5,9,10,7,12,10,9,15,12,13,13,6,19,9,10,6,13,5,13,6,7,2,5,5,2,1,1,1,1,3,0,1\n", + "\n", + "0,1,1,3,1,1,5,5,3,7,2,2,3,12,4,6,8,15,16,16,15,4,14,5,13,10,7,10,6,3,2,3,6,3,3,5,4,3,2,1\n", + "\n", + "0,0,0,2,2,1,3,4,5,5,6,5,5,12,13,5,7,5,11,15,18,7,9,10,14,12,11,9,10,3,2,9,6,2,2,5,3,0,0,1\n", + "\n", + "0,0,1,3,3,1,2,1,8,9,2,8,10,3,8,6,10,13,11,17,19,6,4,11,6,12,7,5,5,4,4,8,2,6,6,4,2,2,0,0\n", + "\n", + "0,1,1,3,4,5,2,1,3,7,9,6,10,5,8,15,11,12,15,6,12,16,6,4,14,3,12,9,6,11,5,8,5,5,6,1,2,1,2,0\n", + "\n", + "0,0,1,3,1,4,3,6,7,8,5,7,11,3,6,11,6,10,6,19,18,14,6,10,7,9,8,5,8,3,10,2,5,1,5,4,2,1,0,1\n", + "\n", + "0,1,1,3,3,4,4,6,3,4,9,9,7,6,8,15,12,15,6,11,6,18,5,14,15,12,9,8,3,6,10,6,8,7,2,5,4,3,1,1\n", + "\n", + "0,1,2,2,4,3,1,4,8,9,5,10,10,3,4,6,7,11,16,6,14,9,11,10,10,7,10,8,8,4,5,8,4,4,5,2,4,1,1,0\n", + "\n", + "0,0,2,3,4,5,4,6,2,9,7,4,9,10,8,11,16,12,15,17,19,10,18,13,15,11,8,4,7,11,6,7,6,5,1,3,1,0,0,0\n", + "\n", + "0,1,1,3,1,4,6,2,8,2,10,3,11,9,13,15,5,15,6,10,10,5,14,15,12,7,4,5,11,4,6,9,5,6,1,1,2,1,2,1\n", + "\n", + "0,0,1,3,2,5,1,2,7,6,6,3,12,9,4,14,4,6,12,9,12,7,11,7,16,8,13,6,7,6,10,7,6,3,1,5,4,3,0,0\n", + "\n", + "0,0,1,2,3,4,5,7,5,4,10,5,12,12,5,4,7,9,18,16,16,10,15,15,10,4,3,7,5,9,4,6,2,4,1,4,2,2,2,1\n", + "\n", + "0,1,2,1,1,3,5,3,6,3,10,10,11,10,13,10,13,6,6,14,5,4,5,5,9,4,12,7,7,4,7,9,3,3,6,3,4,1,2,0\n", + "\n", + "0,1,2,2,3,5,2,4,5,6,8,3,5,4,3,15,15,12,16,7,20,15,12,8,9,6,12,5,8,3,8,5,4,1,3,2,1,3,1,0\n", + "\n", + "0,0,0,2,4,4,5,3,3,3,10,4,4,4,14,11,15,13,10,14,11,17,9,11,11,7,10,12,10,10,10,8,7,5,2,2,4,1,2,1\n", + "\n", + "0,0,2,1,1,4,4,7,2,9,4,10,12,7,6,6,11,12,9,15,15,6,6,13,5,12,9,6,4,7,7,6,5,4,1,4,2,2,2,1\n", + "\n", + "0,1,2,1,1,4,5,4,4,5,9,7,10,3,13,13,8,9,17,16,16,15,12,13,5,12,10,9,11,9,4,5,5,2,2,5,1,0,0,1\n", + "\n", + "0,0,1,3,2,3,6,4,5,7,2,4,11,11,3,8,8,16,5,13,16,5,8,8,6,9,10,10,9,3,3,5,3,5,4,5,3,3,0,1\n", + "\n", + "0,1,1,2,2,5,1,7,4,2,5,5,4,6,6,4,16,11,14,16,14,14,8,17,4,14,13,7,6,3,7,7,5,6,3,4,2,2,1,1\n", + "\n", + "0,1,1,1,4,1,6,4,6,3,6,5,6,4,14,13,13,9,12,19,9,10,15,10,9,10,10,7,5,6,8,6,6,4,3,5,2,1,1,1\n", + "\n", + "0,0,0,1,4,5,6,3,8,7,9,10,8,6,5,12,15,5,10,5,8,13,18,17,14,9,13,4,10,11,10,8,8,6,5,5,2,0,2,0\n", + "\n", + "0,0,1,0,3,2,5,4,8,2,9,3,3,10,12,9,14,11,13,8,6,18,11,9,13,11,8,5,5,2,8,5,3,5,4,1,3,1,1,0\n", + "\n" + ] + } + ], "source": [ + "# using escape characters and relative to access file path\n", "all_paths = [\n", - " \"python/05_src/data/assignment_2_data/inflammation_01.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_02.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_03.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_04.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_05.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_06.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_07.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_08.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_09.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_10.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_11.csv\",\n", - " \"python/05_src/data/assignment_2_data/inflammation_12.csv\"\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", "]\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" + "file_name = f'{all_paths[0]}'\n", + "with open(file_name, 'r') as file:\n", + " # Use the readline() or readlines() method to read the .csv file into a variable\n", + " content_list = file.readlines()\n", + " # Iterate through the variable using a for loop and print each row for inspection\n", + " for data in content_list:\n", + " print(f'{data}')\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 392, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "patient number is 4\n", + "0,1,0,2,4,4,5,1,2,5,5,8,10,12,10,9,15,9,7,9,10,7,5,8,9,6,7,5,11,9,3,8,6,7,5,1,3,0,2,1\n", + "\n", + "0,0,2,1,1,4,4,6,2,4,4,4,7,12,11,15,10,9,12,15,7,17,14,12,6,12,5,11,3,9,7,8,8,3,3,3,1,1,0,1\n", + "\n", + "0,1,0,0,1,2,2,3,4,8,5,2,7,13,14,13,15,16,15,13,18,4,10,11,6,3,14,4,4,6,10,8,6,2,6,2,3,0,0,1\n", + "\n", + "0,1,0,2,1,3,6,1,3,4,10,2,8,11,11,12,14,12,15,15,20,11,12,7,4,15,9,11,9,5,10,7,5,2,3,1,4,2,0,0\n", + "\n", + "0,0,2,2,3,3,5,1,4,2,9,7,5,7,11,10,14,6,9,7,18,15,15,5,6,14,5,5,11,9,8,9,8,1,6,4,2,1,2,1\n", + "\n", + "0,0,0,2,3,4,4,5,3,2,9,8,8,12,11,6,15,8,17,14,20,7,8,10,4,11,9,6,7,7,2,3,5,6,3,4,3,3,0,0\n", + "\n", + "0,1,1,1,3,1,6,4,5,5,2,6,9,13,13,11,10,6,15,16,14,16,14,10,5,9,8,4,9,4,5,9,7,5,6,1,2,1,2,1\n", + "\n", + "0,0,2,3,1,4,6,6,4,5,3,5,10,8,6,8,4,14,7,17,7,5,17,8,10,10,10,3,11,3,9,6,6,7,2,1,3,1,2,1\n", + "\n", + "0,0,2,1,4,4,4,7,5,5,10,8,6,12,14,12,6,6,16,5,6,15,10,5,15,13,13,7,3,11,9,3,7,4,5,4,1,2,1,1\n", + "\n", + "0,1,2,1,2,3,6,1,2,6,10,7,12,6,3,4,4,16,16,18,9,7,10,10,16,12,11,6,3,10,6,8,5,3,4,1,4,2,1,1\n", + "\n", + "0,0,1,3,2,1,1,4,4,5,10,9,6,5,12,13,4,16,11,19,11,15,13,13,9,7,12,5,3,7,8,8,6,2,5,5,3,3,2,1\n", + "\n", + "0,0,1,0,1,3,1,3,4,7,7,8,8,6,7,5,10,12,6,15,15,8,12,8,14,5,5,7,9,4,9,2,3,4,5,3,4,2,2,1\n", + "\n", + "0,1,0,0,2,1,5,1,8,3,7,2,5,13,9,9,10,12,9,5,12,7,5,8,16,5,6,5,4,4,2,2,4,1,3,5,2,1,0,0\n", + "\n", + "0,1,1,2,1,4,2,3,3,9,2,7,6,7,6,3,13,11,13,15,14,15,8,15,14,13,8,9,10,8,5,9,7,4,6,2,4,3,1,0\n", + "\n", + "0,1,1,3,2,4,2,7,3,8,5,9,10,7,9,4,4,5,4,10,13,4,9,9,12,8,7,5,3,4,5,9,6,1,4,1,2,0,0,1\n", + "\n", + "0,0,2,2,4,5,6,2,5,3,5,5,11,6,8,8,6,6,10,17,19,9,11,8,7,11,4,5,12,6,3,8,7,5,2,5,1,3,0,0\n", + "\n", + "0,1,0,2,4,3,6,7,7,9,2,7,9,5,12,7,8,5,15,12,13,16,18,5,13,15,4,8,3,4,7,8,6,1,5,4,2,1,2,0\n", + "\n", + "0,1,1,3,4,5,4,3,4,9,10,5,11,10,7,6,10,7,15,18,14,17,15,16,13,14,6,4,6,8,9,6,5,2,4,5,4,1,2,0\n", + "\n", + "0,0,2,1,3,4,3,6,8,5,6,2,10,11,11,10,5,15,9,18,10,15,11,15,8,15,7,13,7,5,4,3,8,6,5,1,1,0,0,1\n", + "\n", + "0,1,1,0,2,1,4,4,4,5,10,11,12,10,7,10,7,16,16,8,14,18,8,16,7,13,14,12,9,2,10,9,7,7,2,2,3,2,0,0\n", + "\n", + "0,1,0,1,1,2,4,1,4,5,5,7,3,12,10,9,5,5,17,4,8,12,5,11,11,4,13,7,6,4,6,8,7,3,6,5,2,1,1,1\n", + "\n", + "0,0,2,2,2,4,1,4,7,5,8,11,12,5,3,4,6,6,17,17,16,7,4,17,16,4,11,3,11,4,4,2,2,5,3,3,2,1,0,0\n", + "\n", + "0,1,0,1,4,2,6,3,7,6,9,8,4,9,10,7,7,6,6,5,5,13,17,4,11,15,13,3,10,5,10,4,4,2,4,4,2,2,0,0\n", + "\n", + "0,0,2,3,2,4,6,4,3,5,6,5,10,10,8,9,15,16,17,14,5,18,17,6,7,6,7,11,7,10,3,2,5,2,2,3,4,3,1,1\n", + "\n", + "0,0,1,0,1,1,3,1,4,7,8,10,11,11,8,13,9,7,12,14,16,10,10,15,9,4,9,10,3,10,10,9,8,5,2,2,3,3,1,0\n", + "\n", + "0,0,1,1,4,5,3,4,8,2,10,6,6,5,9,3,16,16,18,10,16,19,11,8,15,3,11,3,6,3,3,5,5,2,1,4,3,1,2,0\n", + "\n", + "0,0,2,2,3,5,4,5,5,7,4,2,4,12,11,6,7,17,18,4,10,5,8,15,16,10,7,12,6,4,4,8,2,3,4,3,4,1,2,1\n", + "\n", + "0,0,0,3,2,1,2,7,4,7,10,11,12,3,13,5,6,14,10,16,13,10,11,8,11,13,11,8,12,8,6,3,2,6,5,1,2,1,2,0\n", + "\n", + "0,1,1,2,4,1,5,7,6,5,4,3,11,10,4,10,9,6,16,12,5,4,4,10,9,5,14,5,6,4,2,4,7,6,3,4,4,2,2,1\n", + "\n", + "0,0,2,0,3,3,3,7,2,4,3,8,6,13,5,9,7,12,13,18,8,13,6,6,15,3,10,7,10,7,5,5,3,6,4,5,3,1,0,1\n", + "\n", + "0,0,1,2,4,1,5,7,6,5,4,3,12,12,13,5,15,8,12,5,12,4,7,6,5,9,3,3,7,3,7,7,2,4,4,2,3,3,0,0\n", + "\n", + "0,0,0,0,1,2,6,3,4,2,2,10,3,9,6,10,6,11,11,19,12,15,14,10,15,9,11,7,3,3,8,7,7,7,5,1,3,0,1,1\n", + "\n", + "0,0,2,2,1,1,5,6,6,7,5,7,12,5,7,5,15,11,7,13,15,19,14,13,15,4,11,5,6,7,2,4,7,5,5,5,3,1,1,0\n", + "\n", + "0,0,0,2,1,4,5,3,3,2,7,7,5,4,9,6,16,8,13,12,16,17,5,15,13,6,8,13,12,6,3,7,7,2,2,2,2,1,2,0\n", + "\n", + "0,1,2,1,4,5,5,1,7,6,5,10,9,4,4,5,16,4,5,4,6,9,11,4,4,5,4,8,10,7,6,7,8,1,6,2,4,1,2,1\n", + "\n", + "0,1,2,3,4,2,2,1,3,2,9,2,8,9,8,13,5,11,13,8,20,7,6,15,4,7,14,4,8,9,7,6,3,3,5,5,4,2,0,1\n", + "\n", + "0,0,2,0,4,4,6,3,4,8,4,8,10,13,6,10,10,15,6,13,10,6,16,6,5,3,10,6,9,3,6,7,4,6,1,4,3,2,2,1\n", + "\n", + "0,0,0,2,3,3,3,3,6,7,5,6,10,8,13,5,14,9,11,6,10,17,7,10,15,3,4,10,12,11,7,7,4,5,6,4,1,1,0,0\n", + "\n", + "0,1,2,0,3,1,4,7,8,2,5,4,7,11,11,14,12,17,10,11,5,18,14,14,9,7,5,8,9,7,9,8,2,7,3,1,2,1,2,1\n", + "\n", + "0,0,0,2,1,4,2,1,7,5,9,8,8,6,9,3,11,9,17,6,10,11,17,16,16,10,13,13,6,10,6,9,2,2,2,1,2,0,0,0\n", + "\n", + "0,0,1,2,4,4,3,5,3,3,2,6,9,13,6,13,6,4,15,6,15,11,6,14,6,7,13,4,3,11,4,4,8,4,1,3,2,1,0,0\n", + "\n", + "0,0,2,2,4,5,5,1,5,2,9,6,6,7,14,15,11,17,13,19,18,18,16,4,7,15,6,5,6,8,2,4,6,7,5,5,2,2,2,0\n", + "\n", + "0,0,2,1,2,3,6,5,8,5,3,8,11,4,6,5,15,17,9,7,16,9,18,6,9,13,12,10,6,10,2,7,6,5,3,4,2,0,1,1\n", + "\n", + "0,0,0,2,1,5,4,2,5,6,7,6,6,9,3,15,9,11,14,14,14,10,5,10,11,11,12,10,6,4,8,7,4,5,2,2,3,3,1,1\n", + "\n", + "0,0,0,1,1,1,6,3,3,4,7,7,9,7,14,3,7,8,12,7,6,7,7,6,8,14,4,6,8,10,4,3,3,5,6,5,2,3,1,0\n", + "\n", + "0,0,2,2,4,3,4,2,8,6,2,8,12,9,5,10,11,16,16,14,9,15,7,17,13,11,10,10,3,4,3,6,5,7,3,3,2,2,0,0\n", + "\n", + "0,0,2,0,3,1,4,4,4,4,9,11,4,9,12,15,4,13,9,13,11,17,5,15,8,6,8,3,12,8,7,3,2,7,3,3,4,0,0,1\n", + "\n", + "0,0,0,1,1,3,1,5,4,8,8,5,9,3,14,15,7,11,10,17,20,8,13,10,9,7,6,8,3,2,4,4,3,3,1,1,4,0,0,1\n", + "\n", + "0,1,0,1,4,5,3,7,2,3,9,7,3,11,3,12,6,16,16,13,12,8,14,17,9,13,8,8,9,4,2,8,5,6,1,5,3,2,0,1\n", + "\n", + "0,0,0,1,4,1,5,6,4,9,3,5,7,9,11,15,10,9,8,18,18,19,12,4,6,4,11,11,5,11,10,3,8,5,4,1,4,2,0,1\n", + "\n", + "0,1,1,0,3,4,1,7,7,4,2,8,7,12,14,8,6,8,12,15,18,8,12,17,14,4,12,7,10,8,5,2,8,4,2,4,2,0,1,0\n", + "\n", + "0,1,1,2,2,4,5,2,7,9,7,6,10,9,9,4,16,4,11,12,6,10,16,12,7,11,14,8,12,7,6,7,8,1,4,4,1,0,2,0\n", + "\n", + "0,0,1,3,3,1,3,3,3,2,6,9,6,3,13,15,7,16,17,15,10,16,4,17,8,13,4,10,12,3,5,7,6,6,4,3,4,0,1,0\n", + "\n", + "0,0,0,3,2,3,2,5,8,8,7,4,8,6,8,4,8,4,4,4,9,19,8,9,7,8,10,12,4,11,8,9,6,6,6,3,3,1,1,0\n", + "\n", + "0,0,1,2,3,5,6,4,8,4,10,7,3,6,12,6,6,15,9,19,7,15,16,11,9,9,9,6,8,2,7,7,4,5,6,4,4,0,1,1\n", + "\n", + "0,0,1,0,1,3,5,5,5,3,4,9,10,5,6,5,13,9,4,6,5,16,5,11,5,12,10,5,7,10,6,9,6,3,4,5,3,2,0,0\n", + "\n", + "0,1,1,1,2,2,4,1,2,8,9,8,5,11,3,12,4,7,6,7,5,5,11,12,7,12,5,8,6,10,6,7,4,2,1,4,2,1,0,1\n", + "\n", + "0,0,2,1,3,5,6,2,3,8,6,6,3,3,11,5,4,14,10,11,5,15,10,15,13,12,13,10,3,2,2,5,7,6,1,5,4,0,1,1\n", + "\n", + "0,1,2,3,4,5,1,2,2,6,7,2,4,8,8,14,14,9,13,13,9,8,10,17,14,15,13,13,9,4,2,6,6,3,2,5,4,1,2,1\n", + "\n", + "0,0,1,0,3,4,4,3,3,9,3,2,8,11,8,7,9,15,7,19,16,15,6,16,5,13,9,11,5,3,6,9,5,3,3,2,4,1,0,1\n", + "\n" + ] + } + ], + "source": [ + "import random\n", + "# patient file is chosen randomly\n", + "patient_number = random.randrange(1,12,1)\n", + "print(f'patient number is {patient_number}')\n", + "with open(all_paths[patient_number],'r') as file:\n", + " file_data_list = file.readlines()\n", + " for content in file_data_list:\n", + " print(f'{content}')" ] }, { @@ -130,7 +406,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 393, "metadata": { "id": "82-bk4CBB1w4" }, @@ -140,37 +416,175 @@ "\n", "def patient_summary(file_path, operation):\n", " data = np.loadtxt(fname=file_path, delimiter=',') # Load the data from the file\n", - " ax = 1 # This specifies that the operation should be done for each row (patient)\n", - "\n", + " axis = 1 # This specifies that the operation should be done for each row (patient)\n", + " summary_values=[]\n", + " mean_value =0\n", + " min_value = 0\n", + " max_value = 0\n", + " print(data)\n", + " numbers = np.array(data)\n", " # 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", - "\n", + " # Calculate the mean (average) number of flare-ups for each patient\n", + " mean_value = np.mean(numbers,axis=axis)\n", + " print(f'Mean of patients flare ups {mean_value}')\n", + " summary_values = mean_value\n", " elif operation == 'max':\n", - " # YOUR CODE HERE: Calculate the maximum number of flare-ups experienced by each patient\n", - "\n", + " # Calculate the maximum number of flare-ups experienced by each patient\n", + " max_value = np.max(numbers,axis=1)\n", + " print(f'Max. of patients flare ups {max_value}')\n", + " summary_values = max_value\n", " elif operation == 'min':\n", - " # YOUR CODE HERE: Calculate the minimum number of flare-ups experienced by each patient\n", - "\n", + " # Calculate the minimum number of flare-ups experienced by each patient\n", + " min_value = np.min(numbers,axis=1)\n", + " print(f'Min. of patients flare ups {min_value}')\n", + " summary_values = min_value\n", " else:\n", " # If the operation is not one of the expected values, raise an error\n", " raise ValueError(\"Invalid operation. Please choose 'mean', 'max', or 'min'.\")\n", - "\n", " return summary_values" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 394, "metadata": { "id": "3TYo0-1SDLrd" }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "patient number is 3\n", + "[[0. 1. 2. ... 0. 1. 0.]\n", + " [0. 1. 1. ... 0. 1. 0.]\n", + " [0. 0. 1. ... 2. 1. 0.]\n", + " ...\n", + " [0. 0. 1. ... 0. 1. 0.]\n", + " [0. 0. 2. ... 2. 0. 1.]\n", + " [0. 0. 2. ... 1. 0. 1.]]\n", + "Min. of patients flare ups [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", + " 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", + " 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", + "Min. values for patient Number is 3 are [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", + " 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.\n", + " 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n" + ] + } + ], + "source": [ + "# selecting patient number randomly\n", + "patient_number = random.randint(1,12)\n", + "print(f'patient number is {patient_number}')\n", + "data_min = patient_summary(all_paths[patient_number], 'min')\n", + "print(f'Min. values for patient Number is {patient_number} are {data_min}')" + ] + }, + { + "cell_type": "code", + "execution_count": 395, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "patient number is 2\n", + "[[0. 0. 0. ... 0. 0. 0.]\n", + " [0. 0. 0. ... 1. 0. 0.]\n", + " [0. 0. 1. ... 0. 0. 0.]\n", + " ...\n", + " [0. 0. 1. ... 1. 0. 0.]\n", + " [0. 0. 1. ... 1. 0. 0.]\n", + " [0. 0. 0. ... 0. 0. 0.]]\n", + "Mean of patients flare ups [4. 4.225 3.9 3.7 4.075 3.95 4.55 3.45 3.975 4.525 4.425 4.225\n", + " 3.85 4.925 4.5 3.225 4.4 4.275 4.5 4.125 4.7 5.9 3.975 4.\n", + " 5.275 4.075 4.475 3.7 3.775 3.7 3.925 4.525 4.125 4.025 4.1 4.675\n", + " 5.025 4.9 4.7 4.75 3.975 5.325 3.925 4.4 4.35 4.65 4.1 4.\n", + " 4.4 4.575 3.9 4.65 3.725 4. 4. 5.2 4.325 3.575 4.075 0. ]\n", + "Mean values for patient Number is 2 are [4. 4.225 3.9 3.7 4.075 3.95 4.55 3.45 3.975 4.525 4.425 4.225\n", + " 3.85 4.925 4.5 3.225 4.4 4.275 4.5 4.125 4.7 5.9 3.975 4.\n", + " 5.275 4.075 4.475 3.7 3.775 3.7 3.925 4.525 4.125 4.025 4.1 4.675\n", + " 5.025 4.9 4.7 4.75 3.975 5.325 3.925 4.4 4.35 4.65 4.1 4.\n", + " 4.4 4.575 3.9 4.65 3.725 4. 4. 5.2 4.325 3.575 4.075 0. ]\n" + ] + } + ], + "source": [ + "# selectin patient randomly and choosing Mean option\n", + "patient_number = random.randint(1,12)\n", + "print(f'patient number is {patient_number}')\n", + "data_min = patient_summary(all_paths[patient_number], 'mean')\n", + "print(f'Mean values for patient Number is {patient_number} are {data_min}')" + ] + }, + { + "cell_type": "code", + "execution_count": 396, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "patient number is 6\n", + "[[0. 1. 0. ... 1. 1. 1.]\n", + " [0. 1. 0. ... 0. 0. 1.]\n", + " [0. 0. 1. ... 1. 1. 0.]\n", + " ...\n", + " [0. 1. 2. ... 3. 2. 1.]\n", + " [0. 1. 0. ... 1. 0. 0.]\n", + " [0. 0. 0. ... 3. 0. 1.]]\n", + "Max. of patients flare ups [18. 16. 14. 18. 17. 17. 19. 18. 16. 17. 14. 16. 18. 17. 19. 13. 16. 17.\n", + " 17. 20. 20. 16. 16. 20. 17. 19. 19. 19. 17. 19. 16. 15. 17. 16. 16. 19.\n", + " 16. 18. 18. 13. 18. 18. 17. 17. 14. 19. 20. 15. 19. 16. 16. 20. 17. 17.\n", + " 18. 17. 16. 19. 18. 16.]\n", + "Max. values for patient Number is 6 are [18. 16. 14. 18. 17. 17. 19. 18. 16. 17. 14. 16. 18. 17. 19. 13. 16. 17.\n", + " 17. 20. 20. 16. 16. 20. 17. 19. 19. 19. 17. 19. 16. 15. 17. 16. 16. 19.\n", + " 16. 18. 18. 13. 18. 18. 17. 17. 14. 19. 20. 15. 19. 16. 16. 20. 17. 17.\n", + " 18. 17. 16. 19. 18. 16.]\n" + ] + } + ], + "source": [ + "# selectin patient number randomly and slecting Max option\n", + "patient_number = random.randint(1,12)\n", + "print(f'patient number is {patient_number}')\n", + "data_min = patient_summary(all_paths[patient_number], 'max')\n", + "print(f'Max. values for patient Number is {patient_number} are {data_min}')" + ] + }, + { + "cell_type": "code", + "execution_count": 397, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "patient number is 6\n", + "[[0. 1. 0. ... 1. 1. 1.]\n", + " [0. 1. 0. ... 0. 0. 1.]\n", + " [0. 0. 1. ... 1. 1. 0.]\n", + " ...\n", + " [0. 1. 2. ... 3. 2. 1.]\n", + " [0. 1. 0. ... 1. 0. 0.]\n", + " [0. 0. 0. ... 3. 0. 1.]]\n", + "Value Error ir raised Invalid operation. Please choose 'mean', 'max', or 'min'.\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", - "data_min = patient_summary(all_paths[0], 'min')\n", - "print(len(data_min))" + "# NOT happy path scenario\n", + "try:\n", + " patient_number = random.randint(1,12)\n", + " print(f'patient number is {patient_number}')\n", + " data_min = patient_summary(all_paths[patient_number], 'test')\n", + " print(f'Min. values for patient Number is {patient_number} are {data_min}')\n", + "except ValueError as ex:\n", + " print(f'Value Error ir raised',ex)" ] }, { @@ -228,7 +642,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 398, "metadata": { "id": "_svDiRkdIwiT" }, @@ -236,22 +650,24 @@ "source": [ "# Run this cell so you can use this helper function\n", "\n", - "def check_zeros(x):\n", + "def check_zeros(array):\n", " '''\n", " Given an array, x, check whether any values in x equal 0.\n", " Return True if any values found, else returns False.\n", " '''\n", " # np.where() checks every value in x against the condition (x == 0) and returns a tuple of indices where it was True (i.e. x was 0)\n", - " flag = np.where(x == 0)[0]\n", - "\n", + " # tuple is returned\n", + " status_list = np.where(array == 0)\n", + " print(f'status of patients flare up, type is {status_list}, {type(status_list)}')\n", + " print(f'patients flare up list ***** {status_list[0]}')\n", " # Checks if there are any objects in flag (i.e. not empty)\n", " # If not empty, it found at least one zero so flag is True, and vice-versa.\n", - " return len(flag) > 0" + " return len(status_list[0]) > 0" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 399, "metadata": { "id": "LEYPM5v4JT0i" }, @@ -261,19 +677,79 @@ "\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", - "\n", - " return" + " mean_values = patient_summary(file_path,'mean')\n", + " patientZerosFoundList = check_zeros(mean_values)\n", + " print(f'patients Zeros found *******\\t\\t {patientZerosFoundList}, type is {type(patientZerosFoundList)}')\n", + " return patientZerosFoundList" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 400, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[0. 0. 0. ... 1. 1. 0.]\n", + " [0. 0. 2. ... 0. 2. 1.]\n", + " [0. 1. 2. ... 0. 2. 1.]\n", + " ...\n", + " [0. 0. 2. ... 0. 2. 0.]\n", + " [0. 0. 0. ... 2. 2. 0.]\n", + " [0. 1. 2. ... 3. 2. 0.]]\n", + "Mean of patients flare ups [6.35 5.7 5.9 5.325 6.05 5.675 6.25 5.425 5.35 5.675 5.95 6.375\n", + " 5.475 6.075 6.35 5.725 6.025 6.025 6. 5.975 6.15 5.975 6.125 6.55\n", + " 6.25 6.725 5.325 5.15 6. 6.3 6.25 5.8 5.475 6.125 6.075 5.4\n", + " 6.075 5.45 6.175 6.2 6.175 6.1 5.725 6.375 6.025 5.8 5.8 6.825\n", + " 6.25 5.35 5.575 6. 5.1 5.475 6.9 6.025 6.025 6.55 7.2 6.925]\n", + "status of patients flare up, type is (array([], dtype=int64),), \n", + "patients flare up list ***** []\n", + "patients Zeros found *******\t\t False, type is \n", + "Patients data has no Zeros\n" + ] + } + ], "source": [ "# Test out your code here\n", "# Your output for the first file should be False\n", - "print(detect_problems(all_paths[0]))" + "status = \"Patients flare up has Zeros\" if detect_problems(all_paths[1]) else \"Patients data has no Zeros\"\n", + "print(status)" + ] + }, + { + "cell_type": "code", + "execution_count": 401, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[0. 0. 1. ... 3. 0. 0.]\n", + " [0. 1. 2. ... 1. 0. 1.]\n", + " [0. 1. 1. ... 2. 1. 1.]\n", + " ...\n", + " [0. 1. 1. ... 1. 1. 1.]\n", + " [0. 0. 0. ... 0. 2. 0.]\n", + " [0. 0. 1. ... 1. 1. 0.]]\n", + "Mean of patients flare ups [5.45 5.425 6.1 5.9 5.55 6.225 5.975 6.65 6.625 6.525 6.775 0.\n", + " 6.225 5.75 5.225 6.3 6.55 5.7 5.85 6.55 5.775 5.825 6.175 6.1\n", + " 5.8 6.425 6.05 6.025 6.175 6.55 6.175 6.35 6.725 6.125 7.075 5.725\n", + " 5.925 6.15 6.075 5.75 5.975 5.725 6.3 5.9 6.75 5.925 7.225 6.15\n", + " 5.95 6.275 5.7 6.1 6.825 5.975 6.725 5.7 6.25 6.4 7.05 5.9 ]\n", + "status of patients flare up, type is (array([11], dtype=int64),), \n", + "patients flare up list ***** [11]\n", + "patients Zeros found *******\t\t True, type is \n", + "Patients flare up has Zeros\n" + ] + } + ], + "source": [ + "# inflmmation_01 has modified with test data to reflect zeros\n", + "status = \"Patients flare up has Zeros\" if detect_problems(all_paths[0]) else \"Patients data has no Zeros\"\n", + "print(status)" ] }, { @@ -314,7 +790,8 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3", + "display_name": "dsi_participant", + "language": "python", "name": "python3" }, "language_info": { @@ -327,7 +804,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.9.15" } }, "nbformat": 4, diff --git a/05_src/data/assignment_2_data/inflammation_01.csv b/05_src/data/assignment_2_data/inflammation_01.csv index 07a2e6040..920f7c7cd 100644 --- a/05_src/data/assignment_2_data/inflammation_01.csv +++ b/05_src/data/assignment_2_data/inflammation_01.csv @@ -9,7 +9,7 @@ 0,0,0,3,1,5,6,5,5,8,2,4,11,12,10,11,9,10,17,11,6,16,12,6,8,14,6,13,10,11,4,6,4,7,6,3,2,1,0,0 0,1,1,2,1,3,5,3,5,8,6,8,12,5,13,6,13,8,16,8,18,15,16,14,12,7,3,8,9,11,2,5,4,5,1,4,1,2,0,0 0,1,0,0,4,3,3,5,5,4,5,8,7,10,13,3,7,13,15,18,8,15,15,16,11,14,12,4,10,10,4,3,4,5,5,3,3,2,2,1 -0,1,0,0,3,4,2,7,8,5,2,8,11,5,5,8,14,11,6,11,9,16,18,6,12,5,4,3,5,7,8,3,5,4,5,5,4,0,1,1 +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 0,0,2,1,4,3,6,4,6,7,9,9,3,11,6,12,4,17,13,15,13,12,8,7,4,7,12,9,5,6,5,4,7,3,5,4,2,3,0,1 0,0,0,0,1,3,1,6,6,5,5,6,3,6,13,3,10,13,9,16,15,9,11,4,6,4,11,11,12,3,5,8,7,4,6,4,1,3,0,0 0,1,2,1,1,1,4,1,5,2,3,3,10,7,13,5,7,17,6,9,12,13,10,4,12,4,6,7,6,10,8,2,5,1,3,4,2,0,2,0