Spaces:
Sleeping
Sleeping
import streamlit as st | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# Streamlit app layout | |
st.title("Random Sample Generator and Statistics Calculator") | |
with st.form("my_form"): | |
sample_size = st.number_input("Enter the sample size:", min_value=1, step=1, value=100) | |
low = st.number_input("Enter the lower bound of the uniform distribution:", value=0) | |
high = st.number_input("Enter the upper bound of the uniform distribution:", value=1) | |
if st.form_submit_button("Generate Samples"): | |
# Generate random samples | |
samples = np.random.uniform(low, high, sample_size) | |
# Display the generated samples | |
if "samples" in locals(): | |
st.subheader("Generated Samples") | |
st.write(samples) | |
# Calculate and display descriptive statistics | |
st.subheader("Descriptive Statistics") | |
st.write(f"Mean: {np.mean(samples):.2f}") | |
st.write(f"Standard Deviation: {np.std(samples):.2f}") | |
st.write(f"Variance: {np.var(samples):.2f}") | |
st.write(f"Min: {np.min(samples):.2f}") | |
st.write(f"Max: {np.max(samples):.2f}") | |
# Visualize the distribution with a histogram | |
st.subheader("Histogram") | |
plt.hist(samples, bins=20, color='skyblue', edgecolor='black') | |
plt.xlabel('Value') | |
plt.ylabel('Frequency') | |
plt.title('Histogram of Random Samples') | |
st.pyplot(plt) | |
plt.close() | |
else: | |
st.warning("Please generate samples first.") | |