CoolFace
Apppublic

sabirbagwan/Statistics

sourceHugging Faceupdated 3y agoView on Hugging Face
0likes
app.py64 linesDownload Raw Back to root
1import streamlit as st2import numpy as np3import matplotlib.pyplot as plt4import seaborn as sns5import pandas as pd6 7# Set page title and layout8st.set_page_config(page_title='Statistics Basics', layout='wide')9 10# Set up sidebar11st.sidebar.title('Parameters')12mean = st.sidebar.slider('Mean', min_value=-10.0, max_value=10.0, value=0.0, step=0.1)13std_dev = st.sidebar.slider('Standard Deviation', min_value=0.1, max_value=10.0, value=1.0, step=0.1)14variance = std_dev ** 215variance_slider = st.sidebar.slider('Variance', min_value=0.1, max_value=10.0, value=variance, step=0.1)16 17# Generate data18x = np.linspace(-10, 10, 1000)19y = 1 / (np.sqrt(2 * np.pi * variance_slider)) * np.exp(-0.5 * ((x - mean) ** 2) / variance_slider)20 21# Calculate statistics22median = mean23mode = mean24 25# Generate random values within the curve boundaries based on kernel density estimate26num_points = 100027samples = np.random.choice(x, size=num_points, p=y / np.sum(y))28 29# Create DataFrame for plotting30df = pd.DataFrame({'Values': samples})31 32# Set seaborn style33sns.set(style='darkgrid')34 35# Plot the bell curve and histogram of generated values36fig, ax = plt.subplots(figsize=(10, 6))37sns.histplot(df['Values'], kde=True, color='blue', ax=ax)38sns.kdeplot(df['Values'], color='red', ax=ax)39ax.plot(x, y, linewidth=2, color='red')40ax.set_title('Bell Curve with Histogram and KDE')41ax.set_xlabel('X')42ax.set_ylabel('Density')43 44 45# Display statistics46st.header('Statistics Concepts')47col1, col2, col3, col4, col5 = st.columns(5)48col1.subheader('Mean')49col1.markdown(f"<span style='font-size:24px'>{mean}</span>", unsafe_allow_html=True)50col2.subheader('Median')51col2.markdown(f"<span style='font-size:24px'>{median}</span>", unsafe_allow_html=True)52col3.subheader('Mode')53col3.markdown(f"<span style='font-size:24px'>{mode}</span>", unsafe_allow_html=True)54col4.subheader('St.D')55col4.markdown(f"<span style='font-size:24px'>{std_dev}</span>", unsafe_allow_html=True)56col5.subheader('Variance')57col5.markdown(f"<span style='font-size:24px'>{variance_slider}</span>", unsafe_allow_html=True)58 59 60 61# Display the bell curve, histogram, and KDE plot62st.header('Bell Curve with Histogram and KDE')63st.pyplot(fig)64