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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
st.markdown("""The measure of central tendency is used to find the central average value of the data.The central tendency can be computed by
|
| 2 |
+
useing three ways \n * Mode \n * Median \n * Mean""")
|
| 3 |
+
st.subheader("MODE",divider=True)
|
| 4 |
+
st.markdown("""Mode will be giving the centeral tendency based on most frequently occuring data.The major drawback of mode is its frequecy baised it
|
| 5 |
+
mostly focus on the data which is occuring most times.Here in this mode we might come across some situation's like """)
|
| 6 |
+
st.markdown(''':violet[No_Mode] \n Let's understand why this situation raises for example let's take list of numbers [1,2,3,4,5] here we don't have
|
| 7 |
+
frequency of numbers repeating in this senario we will come accross No_Mode situaton.
|
| 8 |
+
''')
|
| 9 |
+
st.markdown(''':violet[Uni_Mode] \n Let's understand why this situation raises for example let's take list of numbers [1,1,1,2,3,4,5]. here by
|
| 10 |
+
checking the list it will tend to know that the frequency of number 1 is more and it returns the value 1 as output.
|
| 11 |
+
''')
|
| 12 |
+
st.markdown(''':violet[Bi_Mode] \n Let's understand why this situation raises for example let's take list of numbers [1,1,2,2,3,4,5]. here by
|
| 13 |
+
checking the frequency in list we come across a situtaion where we will find two maximun frequecy repeated value hence the output will be Bi_Mode.
|
| 14 |
+
''')
|
| 15 |
+
st.markdown(''':violet[Tri_Mode] \n Let's understand why this situation raises for example let's take list of numbers [1,1,2,2,3,3,4,5]. here by
|
| 16 |
+
checking the frequency in list we come across a situtaion where we will find three maximun frequecy repeated value hence the output will be Tri_Mode.
|
| 17 |
+
''')
|
| 18 |
+
st.markdown(''':violet[Multi_Mode] \n Let's understand why this situation raises for example let's take list of numbers [1,1,2,2,3,3,4,4,5]. here by
|
| 19 |
+
checking the frequency in list we come across a situtaion where we will find more than three maximun frequecy repeated value hence the output will be Multi_Mode.
|
| 20 |
+
''')
|
| 21 |
+
st.title("Calculate Mode")
|
| 22 |
+
def mode(*args):
|
| 23 |
+
list1 = list(args)
|
| 24 |
+
dict1 = {}
|
| 25 |
+
dict2 = {}
|
| 26 |
+
set1 = set(list1)
|
| 27 |
+
for j in set1:
|
| 28 |
+
dict1[j] = list1.count(j)
|
| 29 |
+
max_value = max(dict1.values())
|
| 30 |
+
count = [key for key, value in dict1.items() if value == max_value]
|
| 31 |
+
if max_value == 1:
|
| 32 |
+
return 'no mode'
|
| 33 |
+
elif len(count) == len(set1):
|
| 34 |
+
return 'no mode'
|
| 35 |
+
elif len(count) == 1:
|
| 36 |
+
dict2[count[0]] = dict1.get(count[0])
|
| 37 |
+
return dict2
|
| 38 |
+
elif len(count) == 2:
|
| 39 |
+
return 'bi mode'
|
| 40 |
+
elif len(count) == 3:
|
| 41 |
+
return 'tri mode'
|
| 42 |
+
else:
|
| 43 |
+
return 'multimode'
|
| 44 |
+
numbers_input = st.text_input("Enter a list of numbers separated by commas (e.g., 1, 2, 2, 3, 4):")
|
| 45 |
+
|
| 46 |
+
if numbers_input:
|
| 47 |
+
try:
|
| 48 |
+
list1 = list(map(int, numbers_input.split(',')))
|
| 49 |
+
result = mode(*list1)
|
| 50 |
+
st.write("Mode result:", result)
|
| 51 |
+
except ValueError:
|
| 52 |
+
st.write("Please enter a valid list of numbers separated by commas.")
|
| 53 |
+
st.subheader("Median",divider=True)
|
| 54 |
+
st.markdown("""Median will also be giving the central tendency.But the major drawback of median is it prior foucus will be on the central value.
|
| 55 |
+
In order to find the mean first we have to sort the give list and based on the length of the list the formula are changed""")
|
| 56 |
+
st.subheader("Median Formula for Odd Number of Observations")
|
| 57 |
+
st.latex(r'''
|
| 58 |
+
\text{Median} = X_{\left(\frac{n+1}{2}\right)}
|
| 59 |
+
''')
|
| 60 |
+
st.subheader("Median Formula for Even Number of Observations")
|
| 61 |
+
st.latex(r'''
|
| 62 |
+
\text{Median} = \frac{X_{\left(\frac{n}{2}\right)} + X_{\left(\frac{n}{2}+1\right)}}{2}
|
| 63 |
+
''')
|
| 64 |
+
def median(list1):
|
| 65 |
+
list1.sort()
|
| 66 |
+
length = len(list1)
|
| 67 |
+
if length % 2 == 0:
|
| 68 |
+
mid1 = length // 2 - 1
|
| 69 |
+
mid2 = length // 2
|
| 70 |
+
return (list1[mid1] + list1[mid2]) / 2
|
| 71 |
+
else:
|
| 72 |
+
mid = length // 2
|
| 73 |
+
return list1[mid]
|
| 74 |
+
st.title("Calculate Median")
|
| 75 |
+
numbers_input_1 = st.text_input("Enter a list of numbers separated by commas (e.g., 1, 2, 3, 4, 5):", key="numbers_input_1")
|
| 76 |
+
if numbers_input_1:
|
| 77 |
+
parts = numbers_input_1.split(',')
|
| 78 |
+
list1 = []
|
| 79 |
+
|
| 80 |
+
for num in parts:
|
| 81 |
+
num = num.strip()
|
| 82 |
+
if num.isdigit():
|
| 83 |
+
list1.append(int(num))
|
| 84 |
+
|
| 85 |
+
if list1:
|
| 86 |
+
result = median(list1)
|
| 87 |
+
st.write("Median result:", result)
|
| 88 |
+
else:
|
| 89 |
+
st.write("No valid numbers provided.")
|
| 90 |
+
st.subheader("Mean",divider=True)
|
| 91 |
+
st.markdown("""
|
| 92 |
+
Mean is one of the beautiful measurement of central tendency it invovles all the data present in it.The only drawback of mean is it is
|
| 93 |
+
effected by outliers.Based on the data we will compute the mean in three types""")
|
| 94 |
+
st.subheader("Arthmetic Mean",divider=True)
|
| 95 |
+
st.markdown("""Arthmetic Mean is used on data which have \n * Interval and Ratio Data \n * Symmetric Distributions \n * Data Without Outliers
|
| 96 |
+
""")
|
| 97 |
+
st.subheader("Population Mean Formula")
|
| 98 |
+
st.latex(r'''
|
| 99 |
+
\mu = \frac{1}{N} \sum_{i=1}^{N} x_i
|
| 100 |
+
''')
|
| 101 |
+
st.subheader("Sample Mean Formula")
|
| 102 |
+
st.latex(r'''
|
| 103 |
+
\bar{x} = \frac{1}{n} \sum_{i=1}^{n} x_i
|
| 104 |
+
''')
|
| 105 |
+
def arthamatic_mean(list1):
|
| 106 |
+
sum=reduce(lambda x,y: x+y,list1)
|
| 107 |
+
return sum/len(list1)
|
| 108 |
+
st.title("Calculate Arthmetic_Mean")
|
| 109 |
+
numbers_input_2 = st.text_input("Enter a list of numbers separated by commas (e.g., 1, 2, 3, 4, 5):", key="numbers_input_2")
|
| 110 |
+
if numbers_input_2:
|
| 111 |
+
parts=numbers_input_2.split(",")
|
| 112 |
+
list1=[]
|
| 113 |
+
for i in parts:
|
| 114 |
+
i = i.strip()
|
| 115 |
+
if i.isdigit():
|
| 116 |
+
list1.append(int(i))
|
| 117 |
+
if list1:
|
| 118 |
+
result=arthamatic_mean(list1)
|
| 119 |
+
st.write("Arthmetic_Mean",result)
|
| 120 |
+
else:
|
| 121 |
+
st.write("No valid numbers provided.")
|
| 122 |
+
st.subheader("Geometric Mean",divider=True)
|
| 123 |
+
st.markdown("""Geometric Mean is used on data which have \n * Multiplicative Data \n * Percentages and Rates \n * Normalized Data
|
| 124 |
+
""")
|
| 125 |
+
st.subheader("Geometric Mean for Population")
|
| 126 |
+
st.latex(r'''
|
| 127 |
+
\text{GM}_{\text{population}} = \left( \prod_{i=1}^{N} x_i \right)^{\frac{1}{N}}
|
| 128 |
+
''')
|
| 129 |
+
st.subheader("Geometric Mean for Sample")
|
| 130 |
+
st.latex(r'''
|
| 131 |
+
\text{GM}_{\text{sample}} = \left( \prod_{i=1}^{n} x_i \right)^{\frac{1}{n}}
|
| 132 |
+
''')
|
| 133 |
+
def geometric_mean(list1):
|
| 134 |
+
mul=reduce(lambda x,y: x*y,list1)
|
| 135 |
+
return round(mul**(1/len(list1)),2)
|
| 136 |
+
st.title("Calculate Geometric_Mean")
|
| 137 |
+
numbers_input_3 = st.text_input("Enter a list of numbers separated by commas (e.g., 1, 2, 3, 4, 5):", key="numbers_input_3")
|
| 138 |
+
if numbers_input_3:
|
| 139 |
+
parts=numbers_input_3.split(",")
|
| 140 |
+
list1=[]
|
| 141 |
+
for i in parts:
|
| 142 |
+
i = i.strip()
|
| 143 |
+
if i.isdigit():
|
| 144 |
+
list1.append(int(i))
|
| 145 |
+
if list1:
|
| 146 |
+
result=geometric_mean(list1)
|
| 147 |
+
st.write("Geometric_Mean",result)
|
| 148 |
+
else:
|
| 149 |
+
st.write("No valid numbers provided.")
|
| 150 |
+
st.subheader("Harmonic Mean",divider=True)
|
| 151 |
+
st.markdown("""Harmonic Mean is used on data which have \n * Rates and Ratios \n * Data with Reciprocal Relationships
|
| 152 |
+
""")
|
| 153 |
+
st.subheader("Harmonic Mean for Population")
|
| 154 |
+
st.latex(r'''
|
| 155 |
+
\text{HM}_{\text{population}} = \frac{N}{\sum_{i=1}^{N} \frac{1}{x_i}}
|
| 156 |
+
''')
|
| 157 |
+
st.subheader("Harmonic Mean for Sample")
|
| 158 |
+
st.latex(r'''
|
| 159 |
+
\text{HM}_{\text{sample}} = \frac{n}{\sum_{i=1}^{n} \frac{1}{x_i}}
|
| 160 |
+
''')
|
| 161 |
+
def harmonic_mean(list1):
|
| 162 |
+
sum=reduce(lambda x,y: x+1/y,list1)
|
| 163 |
+
return round(len(list1)/sum,2)
|
| 164 |
+
st.title("Calculate Harmonic_Mean")
|
| 165 |
+
numbers_input_4 = st.text_input("Enter a list of numbers separated by commas (e.g., 1, 2, 3, 4, 5):", key="numbers_input_4")
|
| 166 |
+
if numbers_input_4:
|
| 167 |
+
parts=numbers_input_4.split(",")
|
| 168 |
+
list1=[]
|
| 169 |
+
for i in parts:
|
| 170 |
+
i = i.strip()
|
| 171 |
+
if i.isdigit():
|
| 172 |
+
list1.append(int(i))
|
| 173 |
+
if list1:
|
| 174 |
+
result=harmonic_mean(list1)
|
| 175 |
+
st.write("Geometric_Mean",result)
|
| 176 |
+
else:
|
| 177 |
+
st.write("No valid numbers provided.")
|