Spaces:
Build error
Build error
Commit
·
542c764
1
Parent(s):
68fd2bf
Upload 2 files
Browse files- app.py +63 -0
- requirements.txt +0 -0
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import matplotlib.pyplot as plt
|
| 4 |
+
import seaborn as sns
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
# Set page title and layout
|
| 8 |
+
st.set_page_config(page_title='Statistics Basics', layout='wide')
|
| 9 |
+
|
| 10 |
+
# Set up sidebar
|
| 11 |
+
st.sidebar.title('Parameters')
|
| 12 |
+
mean = st.sidebar.slider('Mean', min_value=-10.0, max_value=10.0, value=0.0, step=0.1)
|
| 13 |
+
std_dev = st.sidebar.slider('Standard Deviation', min_value=0.1, max_value=10.0, value=1.0, step=0.1)
|
| 14 |
+
variance = std_dev ** 2
|
| 15 |
+
variance_slider = st.sidebar.slider('Variance', min_value=0.1, max_value=10.0, value=variance, step=0.1)
|
| 16 |
+
|
| 17 |
+
# Generate data
|
| 18 |
+
x = np.linspace(-10, 10, 1000)
|
| 19 |
+
y = 1 / (np.sqrt(2 * np.pi * variance_slider)) * np.exp(-0.5 * ((x - mean) ** 2) / variance_slider)
|
| 20 |
+
|
| 21 |
+
# Calculate statistics
|
| 22 |
+
median = mean
|
| 23 |
+
mode = mean
|
| 24 |
+
|
| 25 |
+
# Generate random values within the curve boundaries based on kernel density estimate
|
| 26 |
+
num_points = 1000
|
| 27 |
+
samples = np.random.choice(x, size=num_points, p=y / np.sum(y))
|
| 28 |
+
|
| 29 |
+
# Create DataFrame for plotting
|
| 30 |
+
df = pd.DataFrame({'Values': samples})
|
| 31 |
+
|
| 32 |
+
# Set seaborn style
|
| 33 |
+
sns.set(style='darkgrid')
|
| 34 |
+
|
| 35 |
+
# Plot the bell curve and histogram of generated values
|
| 36 |
+
fig, ax = plt.subplots(figsize=(10, 6))
|
| 37 |
+
sns.histplot(df['Values'], kde=True, color='blue', ax=ax)
|
| 38 |
+
sns.kdeplot(df['Values'], color='red', ax=ax)
|
| 39 |
+
ax.plot(x, y, linewidth=2, color='red')
|
| 40 |
+
ax.set_title('Bell Curve with Histogram and KDE')
|
| 41 |
+
ax.set_xlabel('X')
|
| 42 |
+
ax.set_ylabel('Density')
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# Display statistics
|
| 46 |
+
st.header('Statistics Concepts')
|
| 47 |
+
col1, col2, col3, col4, col5 = st.columns(5)
|
| 48 |
+
col1.subheader('Mean')
|
| 49 |
+
col1.markdown(f"<span style='font-size:24px'>{mean}</span>", unsafe_allow_html=True)
|
| 50 |
+
col2.subheader('Median')
|
| 51 |
+
col2.markdown(f"<span style='font-size:24px'>{median}</span>", unsafe_allow_html=True)
|
| 52 |
+
col3.subheader('Mode')
|
| 53 |
+
col3.markdown(f"<span style='font-size:24px'>{mode}</span>", unsafe_allow_html=True)
|
| 54 |
+
col4.subheader('St.D')
|
| 55 |
+
col4.markdown(f"<span style='font-size:24px'>{std_dev}</span>", unsafe_allow_html=True)
|
| 56 |
+
col5.subheader('Variance')
|
| 57 |
+
col5.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 plot
|
| 62 |
+
st.header('Bell Curve with Histogram and KDE')
|
| 63 |
+
st.pyplot(fig)
|
requirements.txt
ADDED
|
File without changes
|