Spaces:
Build error
Build error
| import streamlit as st | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| import pandas as pd | |
| # Set page title and layout | |
| st.set_page_config(page_title='Statistics Basics', layout='wide') | |
| # Set up sidebar | |
| st.sidebar.title('Parameters') | |
| mean = st.sidebar.slider('Mean', min_value=-10.0, max_value=10.0, value=0.0, step=0.1) | |
| std_dev = st.sidebar.slider('Standard Deviation', min_value=0.1, max_value=10.0, value=1.0, step=0.1) | |
| variance = std_dev ** 2 | |
| variance_slider = st.sidebar.slider('Variance', min_value=0.1, max_value=10.0, value=variance, step=0.1) | |
| # Generate data | |
| x = np.linspace(-10, 10, 1000) | |
| y = 1 / (np.sqrt(2 * np.pi * variance_slider)) * np.exp(-0.5 * ((x - mean) ** 2) / variance_slider) | |
| # Calculate statistics | |
| median = mean | |
| mode = mean | |
| # Generate random values within the curve boundaries based on kernel density estimate | |
| num_points = 1000 | |
| samples = np.random.choice(x, size=num_points, p=y / np.sum(y)) | |
| # Create DataFrame for plotting | |
| df = pd.DataFrame({'Values': samples}) | |
| # Set seaborn style | |
| sns.set(style='darkgrid') | |
| # Plot the bell curve and histogram of generated values | |
| fig, ax = plt.subplots(figsize=(10, 6)) | |
| sns.histplot(df['Values'], kde=True, color='blue', ax=ax) | |
| sns.kdeplot(df['Values'], color='red', ax=ax) | |
| ax.plot(x, y, linewidth=2, color='red') | |
| ax.set_title('Bell Curve with Histogram and KDE') | |
| ax.set_xlabel('X') | |
| ax.set_ylabel('Density') | |
| # Display statistics | |
| st.header('Statistics Concepts') | |
| col1, col2, col3, col4, col5 = st.columns(5) | |
| col1.subheader('Mean') | |
| col1.markdown(f"<span style='font-size:24px'>{mean}</span>", unsafe_allow_html=True) | |
| col2.subheader('Median') | |
| col2.markdown(f"<span style='font-size:24px'>{median}</span>", unsafe_allow_html=True) | |
| col3.subheader('Mode') | |
| col3.markdown(f"<span style='font-size:24px'>{mode}</span>", unsafe_allow_html=True) | |
| col4.subheader('St.D') | |
| col4.markdown(f"<span style='font-size:24px'>{std_dev}</span>", unsafe_allow_html=True) | |
| col5.subheader('Variance') | |
| col5.markdown(f"<span style='font-size:24px'>{variance_slider}</span>", unsafe_allow_html=True) | |
| # Display the bell curve, histogram, and KDE plot | |
| st.header('Bell Curve with Histogram and KDE') | |
| st.pyplot(fig) | |