Zmiany
This commit is contained in:
parent
40f642966c
commit
74ee1aff4e
27
zad1/main.py
27
zad1/main.py
@ -3,7 +3,6 @@ Komputerowa analiza danych
|
|||||||
Zadanie 1
|
Zadanie 1
|
||||||
Michał Leśniak 195642
|
Michał Leśniak 195642
|
||||||
"""
|
"""
|
||||||
import math
|
|
||||||
import locale
|
import locale
|
||||||
locale.setlocale(locale.LC_ALL, '')
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
|
|
||||||
@ -26,7 +25,8 @@ def mean(lst):
|
|||||||
return sum/len(lst)
|
return sum/len(lst)
|
||||||
|
|
||||||
|
|
||||||
def median(lst, is_even):
|
def median(lst):
|
||||||
|
is_even = len(lst) % 2 == 0
|
||||||
return (lst[len(lst)//2-1]+lst[len(lst)//2])/2 if is_even else lst[len(lst)//2]
|
return (lst[len(lst)//2-1]+lst[len(lst)//2])/2 if is_even else lst[len(lst)//2]
|
||||||
|
|
||||||
|
|
||||||
@ -34,25 +34,27 @@ def sample_standard_deviation(lst, lst_mean):
|
|||||||
sum = 0
|
sum = 0
|
||||||
for x in [(y-lst_mean)**2 for y in lst]:
|
for x in [(y-lst_mean)**2 for y in lst]:
|
||||||
sum += x
|
sum += x
|
||||||
return math.sqrt(sum/(len(lst)-1))
|
return (sum/(len(lst)-1))**0.5
|
||||||
|
|
||||||
|
|
||||||
def q1(lst, is_even, lst_median):
|
def q1(lst, lst_median):
|
||||||
idx = len(lst)//2-1 if is_even else len(lst)//2+1
|
is_even = len(lst) % 2 == 0
|
||||||
|
idx = len(lst)//2 if is_even else len(lst)//2+1
|
||||||
sorted_list = lst[:idx]
|
sorted_list = lst[:idx]
|
||||||
if is_even:
|
if is_even:
|
||||||
sorted_list.append(lst_median)
|
sorted_list.append(lst_median)
|
||||||
|
|
||||||
return median(sorted_list, is_even)
|
return median(sorted_list)
|
||||||
|
|
||||||
|
#
|
||||||
def q3(lst, is_even, lst_median):
|
def q3(lst, lst_median):
|
||||||
|
is_even = len(lst) % 2 == 0
|
||||||
idx = len(lst)//2+1 if is_even else len(lst)//2
|
idx = len(lst)//2+1 if is_even else len(lst)//2
|
||||||
sorted_list = lst[idx:]
|
sorted_list = lst[idx:]
|
||||||
if is_even:
|
if is_even:
|
||||||
sorted_list.insert(0, lst_median)
|
sorted_list.insert(0, lst_median)
|
||||||
|
|
||||||
return median(sorted_list, is_even)
|
return median(sorted_list)
|
||||||
|
|
||||||
|
|
||||||
def min(lst):
|
def min(lst):
|
||||||
@ -64,10 +66,10 @@ def max(lst):
|
|||||||
|
|
||||||
|
|
||||||
def calc_data(lst):
|
def calc_data(lst):
|
||||||
is_even = len(lst) % 2 == 0
|
|
||||||
lst_mean = mean(lst)
|
lst_mean = mean(lst)
|
||||||
lst_median = median(lst, is_even)
|
lst_median = median(lst)
|
||||||
return min(lst), lst_mean, sample_standard_deviation(lst, lst_mean), lst_median, q1(lst, is_even, lst_median), q3(lst, is_even, lst_median), max(lst)
|
return min(lst), lst_mean, sample_standard_deviation(lst, lst_mean), lst_median, \
|
||||||
|
q1(lst, lst_median), q3(lst, lst_median), max(lst)
|
||||||
|
|
||||||
|
|
||||||
def calc_species_data(species):
|
def calc_species_data(species):
|
||||||
@ -184,6 +186,7 @@ def main():
|
|||||||
petal_width_list.append(float(petal_width))
|
petal_width_list.append(float(petal_width))
|
||||||
species_dict[species] += 1
|
species_dict[species] += 1
|
||||||
|
|
||||||
|
|
||||||
sepal_length_list.sort()
|
sepal_length_list.sort()
|
||||||
sepal_width_list.sort()
|
sepal_width_list.sort()
|
||||||
petal_length_list.sort()
|
petal_length_list.sort()
|
||||||
|
Loading…
Reference in New Issue
Block a user