diff --git a/UFCFVQ-15-M Programming Task 1.ipynb b/UFCFVQ-15-M Programming Task 1.ipynb index 7709324229324a10a6ff7dba8355f4a0b5729f26..e3d2c151008db46337be740d2fcbb1389dc074df 100644 --- a/UFCFVQ-15-M Programming Task 1.ipynb +++ b/UFCFVQ-15-M Programming Task 1.ipynb @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 27, "metadata": {}, "outputs": [ { @@ -51,7 +51,7 @@ "#Converting all string numbers to (integer)\n", "List = list(map(int, ConvertToList))\n", "#Now all numbers are integer niside the list e.g [148, 85, 183]\n", - "print(f'3) The items inside {type(List)} is {type(List[0])} | Now its a list of integer') " + "print(f'3) The items inside {type(List)} is {type(List[0])} | Now its a list of integer')" ] }, { @@ -63,31 +63,31 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "The mean of the list = 120.89453125\n" + "The mean of the datan list is 120.89453125\n" ] } ], "source": [ - "#function to get the mean of a python list\n", + "#function to get the mean of a given python list\n", "def meanFinder(List):\n", - " #assining the varivale to be global so it can be called any were else (as it has been called in FR1.7)\n", + " #assining the variable to be global so it can be called any were else (as it has been called in FR1.7)\n", " global ListMean\n", - " \n", + "\n", " #Find the mean of the list using the mathematical mean equation\n", " ListMean = sum(List)/len(List)\n", - " \n", + "\n", " #Rturn The result\n", " return ListMean\n", "\n", "#Calling the function and passing the >> List << argument to it \n", - "print(f'The mean of the list = {meanFinder(List)}')" + "print(f'The mean of the datan list is {meanFinder(List)}')" ] }, { @@ -107,19 +107,19 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Standard Devision of the list = 31.95179590820272\n" + "Standard Devision of the data list is 31.95179590820272\n" ] } ], "source": [ - "#Function to find the standard deviation\n", + "#Function to find the standard deviation of a given python list\n", "def StdDevFinder(List): \n", " #Find the variance among the list using its mathematical equation\n", " # (Square each deviation from the mean & Calculate the variance)\n", @@ -129,9 +129,8 @@ " #Rturn The result\n", " return STD_DEV\n", "\n", - "\n", "#Calling the function and passing the >> List << argument to it \n", - "print(f'Standard Devision of the list = {StdDevFinder(List)}')" + "print(f'Standard Devision of the data list is {StdDevFinder(List)}')" ] }, { @@ -151,15 +150,15 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "The minimum number in the list = 0\n", - "The maximum in the list = 199\n" + "The minimum number in the data list is 0\n", + "The maximum in the data list is 199\n" ] } ], @@ -177,9 +176,9 @@ "\n", " \n", "#Calling the functions and passing the >> List << argument to it \n", - "print(f'The minimum number in the list = {MinFinder(List)}')\n", + "print(f'The minimum number in the data list is {MinFinder(List)}')\n", "\n", - "print(f'The maximum in the list = {MaxFinder(List)}')\n" + "print(f'The maximum in the data list is {MaxFinder(List)}')\n" ] }, { @@ -200,7 +199,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -211,11 +210,11 @@ " ListNumber = len(List)\n", " #Multiplying the length with the percentile number and dividing it by 100 (percentile equation) \n", " Listpercentile = ListNumber * percentile / 100\n", - " #If the number inside the (List Percentile) is integer, sort it and return it to (List Percentile list)\n", + " #If the number inside the (ListPercentile) is integer, sort it and return it to (List Percentile list)\n", " if Listpercentile.is_integer():\n", " Listpercentile = sorted(List)[int(Listpercentile)]\n", " return Listpercentile\n", - " #else, remove it from (List Percentile list)\n", + " #else, remove it from (ListPercentile list)\n", " else:\n", " Listpercentile = sorted(List)[int(round(Listpercentile)) -1]\n", " return Listpercentile" @@ -230,7 +229,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -265,7 +264,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -300,7 +299,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -335,7 +334,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -391,15 +390,13 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 31, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[+] File Size >>> 3.638 (KB) | 3638 Bytes | 0.003638 (MB)\n", - "\n", "[+] The data type is <class 'list'> and the numbers inside is <class 'int'>\n", "\n", "[+] The file content as shown:\n", @@ -416,19 +413,9 @@ "ConvertToList = list(FileName.strip().split())\n", "#Converting it to integer list\n", "List = list(map(int, ConvertToList))\n", - "\n", - "#Finding the file size inside the computer memory\n", - "def getSize(file):\n", - " file.seek(0,2) #To count from the from the start of the file, and stop at the end.\n", - " FileSize = file.tell() # To get file position\n", - " #Print file size\n", - " print(f'[+] File Size >>> {FileSize*0.001} (KB) | {FileSize} Bytes | {round(FileSize*0.000001,6)} (MB)\\n')\n", " \n", - "FileName = open('task1.dat','r')\n", - "getSize(FileName)\n", - "\n", "print(f'[+] The data type is {type(List)} and the numbers inside is {type(List[0])}\\n')\n", - "print(f\"[+] The file content as shown:\\n\\n{List[0:]}\")\n" + "print(f\"[+] The file content as shown:\\n\\n{List[:]}\")\n" ] }, { @@ -451,40 +438,12 @@ "metadata": {}, "source": [ "Following the given instruction in the appendix.A (output structure), this task has been created.\n", - "To be visualised better, the data output has been limited to 10 in each row." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "##### Explanation 1 Example for \"EachClmToList\"\n", - "\n", - "['A','B','C'],\n", - "\n", - "['1','2','3'],\n", - "\n", - "['4','5','6'],so on..\n", - "\n", - "Therfore EachClmToList[0] = ['A','1','4'..]\n", - "\n", - "##### Explanation 2\n", - "For loop is created to reach out to every single data inside 'AppendTolist' in the range of the data length,\n", - "(768) or (767) if we count from 0. To be able to do so, 2 for loop should be created as shown, one to count the number of\n", - "columns which is (9) or 8 if we count the zero, and the other to count the number of data in each row.\n", - "therefore it will start from [0][0].. [1][0].. [2][0] until it reaches [767][0] and switch to [0][1]..\n", - "and continue until it reaches the last data in the file which is at [767][8].\n", - "while so, the data (numbers) will be appended to a new list called 'EachClmToList'\n", - "\n", - "##### Explanation 3\n", - "A mathematical operation to create a sublist of (each data under each line for the header ) to achieve exploration 1, therefore\n", - "for every end of a line create a new list for the next line, and at the end, we will have a total of 9 lists that \n", - "achieved to carry each column of data into one list " + "To be visualised better, the data output has been limited to 13 in each row." ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 60, "metadata": {}, "outputs": [], "source": [ @@ -492,7 +451,7 @@ "AppendTolist = [] #Creating an empty list to append all the CSV data inside it\n", "ColumnHeader = [] #Creating an empty list to append the CSV Column Header (Name of each column)\n", "\n", - "#Refer to Explanation (1)\n", + "#Refer to Explanation (1) at the end\n", "EachClmToList = [] #Creating an empty list to append Each column-row (each data under each line for the header ) \n", "\n", "'''\n", @@ -504,28 +463,31 @@ " AppendTolist.append(data) #Append (adding) the new data into the 'AppendTolist' list\n", "#print(AppendTolist[0:5])\n", "\n", - "#For loop to append only the first list >> [0] << of the 'AppendTolist', which is the columns header to another list.\n", + "#For loop to append only the first list >> [0] << of the 'AppendTolist', which is the header row (names).\n", "for subList in AppendTolist[0]: \n", " ColumnHeader.append(subList) #append to another list. \n", - "#Removing the appended it from the main list 'AppendTolist'\n", + "#Removing the names row from the main list 'AppendTolist'\n", "AppendTolist.remove(AppendTolist[0])\n", "\n", - "#Refer to Explanation (2) \n", + "#Refer to Explanation (2) at the end\n", "for clmLen in range(len(ColumnHeader)): #9 aka 8 as it starts from 0\n", " #print(ColumnHeader)\n", " for RowLen in range(len(AppendTolist)):#768 aka 767 as it satrts from 0 \n", - " #print(AppendTolist[767][8])\n", + " #print(AppendTolist[RowLen][clmLen])\n", " EachClmToList.append(AppendTolist[RowLen][clmLen]) \n", "#print(EachClmToList)\n", "\n", "#to avoid python errors, a new variable is created called 'numberOfDataInEach' that carries row length in each line.\n", "numberOfDataInEach = len(AppendTolist)\n", "\n", - "#Refer to Explanation (3)\n", + "#Refer to Explanation (3) at the end\n", "EachClmToList = [EachClmToList[x:x+numberOfDataInEach] for x in range(0, len(EachClmToList), numberOfDataInEach)]\n", "\n", "\n", - "#As per as requested the data is stored in the memory and can be called later for analyzing" + "#As per as requested the data is stored in the memory and can be called later for analyzing\n", + "\n", + "#but for proven of successful output, the data can be printed out by uncommenting the next line\n", + "#print(ColumnHeader,EachClmToList[:][:])" ] }, { @@ -545,33 +507,33 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 71, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "\"Pregnancies\" : [6.0, 1.0, 8.0, 1.0, 0.0, 5.0, 3.0, 10.0, 2.0, 8.0]\n", - "\"Glucose\" : [148.0, 85.0, 183.0, 89.0, 137.0, 116.0, 78.0, 115.0, 197.0, 125.0]\n", - "\"BloodPressure\" : [72.0, 66.0, 64.0, 66.0, 40.0, 74.0, 50.0, 0.0, 70.0, 96.0]\n", - "\"SkinThickness\" : [35.0, 29.0, 0.0, 23.0, 35.0, 0.0, 32.0, 0.0, 45.0, 0.0]\n", - "\"Insulin\" : [0.0, 0.0, 0.0, 94.0, 168.0, 0.0, 88.0, 0.0, 543.0, 0.0]\n", - "\"BMI\" : [33.6, 26.6, 23.3, 28.1, 43.1, 25.6, 31.0, 35.3, 30.5, 0.0]\n", - "\"DiabetesPedigreeFunction\" : [0.627, 0.351, 0.672, 0.167, 2.288, 0.201, 0.248, 0.134, 0.158, 0.232]\n", - "\"Age\" : [50.0, 31.0, 32.0, 21.0, 33.0, 30.0, 26.0, 29.0, 53.0, 54.0]\n", - "\"Outcome\" : [1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0]\n" + "\"Pregnancies\" : [6.0, 1.0, 8.0, 1.0, 0.0, 5.0, 3.0, 10.0, 2.0, 8.0, 4.0, 10.0, 10.0]\n", + "\"Glucose\" : [148.0, 85.0, 183.0, 89.0, 137.0, 116.0, 78.0, 115.0, 197.0, 125.0, 110.0, 168.0, 139.0]\n", + "\"BloodPressure\" : [72.0, 66.0, 64.0, 66.0, 40.0, 74.0, 50.0, 0.0, 70.0, 96.0, 92.0, 74.0, 80.0]\n", + "\"SkinThickness\" : [35.0, 29.0, 0.0, 23.0, 35.0, 0.0, 32.0, 0.0, 45.0, 0.0, 0.0, 0.0, 0.0]\n", + "\"Insulin\" : [0.0, 0.0, 0.0, 94.0, 168.0, 0.0, 88.0, 0.0, 543.0, 0.0, 0.0, 0.0, 0.0]\n", + "\"BMI\" : [33.6, 26.6, 23.3, 28.1, 43.1, 25.6, 31.0, 35.3, 30.5, 0.0, 37.6, 38.0, 27.1]\n", + "\"DiabetesPedigreeFunction\" : [0.627, 0.351, 0.672, 0.167, 2.288, 0.201, 0.248, 0.134, 0.158, 0.232, 0.191, 0.537, 1.441]\n", + "\"Age\" : [50.0, 31.0, 32.0, 21.0, 33.0, 30.0, 26.0, 29.0, 53.0, 54.0, 30.0, 34.0, 57.0]\n", + "\"Outcome\" : [1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0]\n" ] } ], "source": [ "#Creating function to construct the data structure and to call it after. \n", - "def dataStrcuture():\n", + "def DataDemonstration():\n", " for x in range(len(ColumnHeader)):\n", - " print(f'\"{ColumnHeader[x]}\" : {list(map(float,EachClmToList[x][:10]))}') #numbers has been converted to float\n", - " #Only 10 data have been printed to better visualize the result, for the whole result remove [:10], [:] or none\n", - " #list(map(float,EachClmToList[x][:10]))\n", - "dataStrcuture()" + " print(f'\"{ColumnHeader[x]}\" : {list(map(float,EachClmToList[x][:13]))}') #numbers has been converted to float\n", + " #Only 13 data have been printed to better visualize the result, for the whole result remove [:13], which will be\n", + " #list(map(float,EachClmToList[x]))\n", + "DataDemonstration()" ] }, { @@ -591,7 +553,7 @@ }, { "cell_type": "code", - "execution_count": 91, + "execution_count": 87, "metadata": {}, "outputs": [ { @@ -614,9 +576,10 @@ ], "source": [ "print('\"Stats\" : [\"Mean\",\"Stdev\", \"Min\", Max\",\"25%\",\"50%\",\"75%\"]\\n')\n", - "#Calling the file \n", - "def dataStrcuture():\n", - " global data\n", + "\n", + "#function for Data Statistical\n", + "def DataStatistical():\n", + "\n", " #Creating an empty list to append Each column-row (each data under each line for the header ) \n", " ConvertdeToFloat = []\n", "\n", @@ -624,10 +587,8 @@ " for x in range(len(ColumnHeader)):\n", " EachClmInListToFloat = list(map(float,EachClmToList[x][:]))\n", " ConvertdeToFloat.append(EachClmInListToFloat)\n", - " \n", - " \n", - " #Creating variables that contains the required information to create the data structure\n", - " #and calling function that has been saved in memory before. \n", + "\n", + " #Creating variables that contains the required information to create the datas tatistical structure\n", " \n", " for x in range(len(ColumnHeader)):\n", " data = [round(meanFinder(ConvertdeToFloat[x][:]),3),\n", @@ -640,7 +601,7 @@ " ]\n", " print(f'\"{ColumnHeader[x]}\" : {data}')\n", " \n", - "dataStrcuture()" + "DataStatistical()" ] }, { @@ -660,7 +621,7 @@ }, { "cell_type": "code", - "execution_count": 94, + "execution_count": 76, "metadata": {}, "outputs": [ { @@ -684,14 +645,16 @@ } ], "source": [ - "#Calling the file \n", - "def dataStrcuture():\n", + "#Function to print out a custom statistical table\n", + "def DataCustomStatistical():\n", " \n", + " #DiabetesPedigreeFunction name is changed to DiabPedFnc as it takes a lot of space to print it out.\n", " newList = [element.replace('DiabetesPedigreeFunction', 'DiabPedFnc') for element in ColumnHeader]\n", " clmName = [newList]\n", + " \n", " Status = [\"Mean\",\"Stdev\", \"Min\", \"Max\",\"25%\",\"50%\",\"75%\"]\n", " format_row = \"{: >13} \" * (len(Status)+1)\n", - " print(stars.rjust(121,'*'))\n", + " print(stars.rjust(121,'*')) #Printing the stars\n", " print(format_row.format(\"Status\", *Status))\n", " print(stars.rjust(121,'*'))\n", "\n", @@ -708,7 +671,7 @@ " #and calling function that has been saved in memory before.\n", " \n", " for x in range(len(ColumnHeader)):\n", - "\n", + " \n", " data = [[round(meanFinder(ConvertdeToFloat[x][:]),3),\n", " round(StdDevFinder((ConvertdeToFloat[x][:])),3),\n", " MaxFinder(ConvertdeToFloat[x][:]),\n", @@ -720,13 +683,12 @@ "\n", " format_row = \"{:>15}\" * (len(Status) + 1)\n", " \n", - " for names, row in zip(clmName, data):\n", + " for names, row in zip(clmName, data): #Printing the result out formatted to have an organized custom table\n", " #print(team[x])\n", " print(format_row.format(names[x], *row))\n", "\n", - "\n", - "dataStrcuture()\n", "stars = '*'\n", + "DataCustomStatistical()\n", "print(stars.rjust(121,'*'))" ] }, @@ -749,14 +711,47 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "in FR1.2 there is another formula for STd.Dev. we can use that also" + "### Explanation\n", + "##### Explanation 1 \n", + "Normal data structure is as shown \n", + "\n", + "['A','B','C'],\n", + "\n", + "['1','2','3'],\n", + "\n", + "['4','5','6'],so on..\n", + "\n", + "Therfore EachClmToList[0] = ['A','1','4'..]\n", + "\n", + "##### Explanation 2\n", + "For loop is created to reach out to every single data inside 'AppendTolist' in the range of the data length,\n", + "(768) or (767) if we count from 0. To be able to do so, 2 for loop should be created as shown, one to count the number of\n", + "columns which is (9) or 8 if we count the zero, and the other to count the number of data in each row.\n", + "therefore it will start from [0][0].. [1][0].. [2][0] until it reaches [767][0] and switch to [0][1]..\n", + "and continue until it reaches the last data in the file which is at [767][8].\n", + "while so, the data (numbers) will be appended to a new list called 'EachClmToList'\n", + "\n", + "##### Explanation 3\n", + "A mathematical operation to create a sublist of (each data under each line for the header ) to achieve exploration 1, therefore\n", + "for every end of a line create a new list for the next line, and at the end, we will have a total of 9 lists that \n", + "achieved to carry each column of data into one list \n", + "\n", + "\n", + "#### From task 1.1 to 1.7\n", + "\n", + "Overall the qustions can be solved using mathmatical quations using pre-build function in python\n", + "\n", + "#### For task 1.9 and along\n", + "\n", + "\n", + "\n", + "### Strength \n", + "### Weaknesses\n", + "### Improvement Points \n", + "### Alternative\n", + "\n" ] }, - { - "cell_type": "raw", - "metadata": {}, - "source": [] - }, { "cell_type": "markdown", "metadata": {},