import streamlit as st
import pandas as pd
import numpy as np
from functools import reduce
st.markdown("""
""", unsafe_allow_html=True)
st.title("Measure Of Central Tendency")
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
useing three ways
""",unsafe_allow_html=True)
st.subheader("MODE")
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
mostly focus on the data which is occuring most times.Here in this mode we might come across some situation's like """,unsafe_allow_html=True)
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
frequency of numbers repeating in this senario we will come accross No_Mode situaton.
''',unsafe_allow_html=True)
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
checking the list it will tend to know that the frequency of number 1 is more and it returns the value 1 as output.
''',unsafe_allow_html=True)
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
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.
''',unsafe_allow_html=True)
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
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.
''',unsafe_allow_html=True)
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
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.
''',unsafe_allow_html=True)
st.title("Calculate Mode")
def mode(*args):
list1 = list(args)
dict1 = {}
dict2 = {}
set1 = set(list1)
for j in set1:
dict1[j] = list1.count(j)
max_value = max(dict1.values())
count = [key for key, value in dict1.items() if value == max_value]
if max_value == 1:
return 'no mode'
elif len(count) == len(set1):
return 'no mode'
elif len(count) == 1:
dict2[count[0]] = dict1.get(count[0])
return dict2
elif len(count) == 2:
return 'bi mode'
elif len(count) == 3:
return 'tri mode'
else:
return 'multimode'
numbers_input = st.text_input("Enter a list of numbers separated by commas (e.g., 1, 2, 2, 3, 4):")
if numbers_input:
try:
list1 = list(map(int, numbers_input.split(',')))
result = mode(*list1)
st.write("Mode result:", result)
except ValueError:
st.write("Please enter a valid list of numbers separated by commas.")
st.subheader("Median")
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.
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""",unsafe_allow_html=True)
st.subheader("Median Formula for Odd Number of Observations")
st.latex(r'''
\text{Median} = X_{\left(\frac{n+1}{2}\right)}
''')
st.subheader("Median Formula for Even Number of Observations")
st.latex(r'''
\text{Median} = \frac{X_{\left(\frac{n}{2}\right)} + X_{\left(\frac{n}{2}+1\right)}}{2}
''')
def median(numbers):
numbers.sort()
length = len(numbers)
if length % 2 == 0:
mid1 = length // 2 - 1
mid2 = length // 2
return (numbers[mid1] + numbers[mid2]) / 2
else:
mid = length // 2
return numbers[mid]
st.title("Calculate Median")
range_values = st.slider('Select a range of values', 0, 100, (25, 75))
numbers_input = list(range(range_values[0], range_values[1] + 1))
if numbers_input:
result = median(numbers_input)
st.write("Median result:", result)
else:
st.write("No valid numbers provided.")
st.subheader("Mean")
st.markdown("""
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
effected by outliers.Based on the data we will compute the mean in three types""",unsafe_allow_html=True)
st.subheader("Arthmetic Mean")
st.markdown("""Arthmetic Mean is used on data which have
- Interval and Ratio Data
- Symmetric Distributions
- Data Without Outliers
""",unsafe_allow_html=True)
st.subheader("Arthmetic Mean for Population")
st.latex(r'''
\mu = \frac{1}{N} \sum_{i=1}^{N} x_i
''')
st.subheader("Arthmetic Mean for Sample")
st.latex(r'''
\bar{x} = \frac{1}{n} \sum_{i=1}^{n} x_i
''')
def arthamatic_mean(list1):
sum=reduce(lambda x,y: x+y,list1)
return sum/len(list1)
st.title("Calculate Arthmetic_Mean")
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")
if numbers_input_2:
parts=numbers_input_2.split(",")
list1=[]
for i in parts:
i = i.strip()
if i.isdigit():
list1.append(int(i))
if list1:
result=arthamatic_mean(list1)
st.write("Arthmetic_Mean",result)
else:
st.write("No valid numbers provided.")
st.subheader("Geometric Mean")
st.markdown("""Geometric Mean is used on data which have
- Multiplicative Data
- Percentages and Rates
- Normalized Data
""",unsafe_allow_html=True)
st.subheader("Geometric Mean for Population")
st.latex(r'''
\text{GM}_{\text{population}} = \left( \prod_{i=1}^{N} x_i \right)^{\frac{1}{N}}
''')
st.subheader("Geometric Mean for Sample")
st.latex(r'''
\text{GM}_{\text{sample}} = \left( \prod_{i=1}^{n} x_i \right)^{\frac{1}{n}}
''')
def geometric_mean(list1):
mul=reduce(lambda x,y: x*y,list1)
return round(mul**(1/len(list1)),2)
st.title("Calculate Geometric_Mean")
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")
if numbers_input_3:
parts=numbers_input_3.split(",")
list1=[]
for i in parts:
i = i.strip()
if i.isdigit():
list1.append(int(i))
if list1:
result=geometric_mean(list1)
st.write("Geometric_Mean",result)
else:
st.write("No valid numbers provided.")
st.subheader("Harmonic Mean")
st.markdown("""Harmonic Mean is used on data which have
- Rates and Ratios
- Data with Reciprocal Relationships
""",unsafe_allow_html=True)
st.subheader("Harmonic Mean for Population")
st.latex(r'''
\text{HM}_{\text{population}} = \frac{N}{\sum_{i=1}^{N} \frac{1}{x_i}}
''')
st.subheader("Harmonic Mean for Sample")
st.latex(r'''
\text{HM}_{\text{sample}} = \frac{n}{\sum_{i=1}^{n} \frac{1}{x_i}}
''')
def harmonic_mean(list1):
sum=reduce(lambda x,y: x+1/y,list1)
return round(len(list1)/sum,2)
st.title("Calculate Harmonic_Mean")
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")
if numbers_input_4:
parts=numbers_input_4.split(",")
list1=[]
for i in parts:
i = i.strip()
if i.isdigit():
list1.append(int(i))
if list1:
result=harmonic_mean(list1)
st.write("Geometric_Mean",result)
else:
st.write("No valid numbers provided.")