File size: 1,476 Bytes
e502f76
 
9169168
e502f76
 
fdfe2d0
e502f76
 
fdfe2d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b0d34f3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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.")