Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,53 +3,36 @@ import numpy as np
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
# Streamlit app layout
|
6 |
-
st.title("
|
7 |
|
8 |
with st.form("my_form"):
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
if st.form_submit_button("Generate
|
13 |
-
# Generate
|
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 |
-
st.write(f"Covariance between Set 1 and Set 2: {cov_set:.2f}")
|
40 |
-
|
41 |
-
# Plotting
|
42 |
-
st.subheader("Scatter Plot")
|
43 |
-
st.write("Scatter plot of Set 1 against Set 2")
|
44 |
-
st.write("You can visualize the relationship between the two sets")
|
45 |
-
st.write("Note: This plot requires 'matplotlib' which may not be supported in all Streamlit deployment environments.")
|
46 |
-
|
47 |
-
# Create the scatter plot
|
48 |
-
fig, ax = plt.subplots()
|
49 |
-
ax.scatter(set1, set2)
|
50 |
-
ax.set_xlabel("Set 1")
|
51 |
-
ax.set_ylabel("Set 2")
|
52 |
-
st.pyplot(fig)
|
53 |
-
|
54 |
-
else:
|
55 |
-
st.write(":red[Please specify the number of data points]")
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
# Streamlit app layout
|
6 |
+
st.title("Random Sample Generator and Statistics Calculator")
|
7 |
|
8 |
with st.form("my_form"):
|
9 |
+
sample_size = st.number_input("Enter the sample size:", min_value=1, step=1, value=100)
|
10 |
+
low = st.number_input("Enter the lower bound of the uniform distribution:", value=0)
|
11 |
+
high = st.number_input("Enter the upper bound of the uniform distribution:", value=1)
|
12 |
+
if st.form_submit_button("Generate Samples"):
|
13 |
+
# Generate random samples
|
14 |
+
samples = np.random.uniform(low, high, sample_size)
|
15 |
+
|
16 |
+
# Display the generated samples
|
17 |
+
if "samples" in locals():
|
18 |
+
st.subheader("Generated Samples")
|
19 |
+
st.write(samples)
|
20 |
+
|
21 |
+
# Calculate and display descriptive statistics
|
22 |
+
st.subheader("Descriptive Statistics")
|
23 |
+
st.write(f"Mean: {np.mean(samples):.2f}")
|
24 |
+
st.write(f"Standard Deviation: {np.std(samples):.2f}")
|
25 |
+
st.write(f"Variance: {np.var(samples):.2f}")
|
26 |
+
st.write(f"Min: {np.min(samples):.2f}")
|
27 |
+
st.write(f"Max: {np.max(samples):.2f}")
|
28 |
+
|
29 |
+
# Visualize the distribution with a histogram
|
30 |
+
st.subheader("Histogram")
|
31 |
+
plt.hist(samples, bins=20, color='skyblue', edgecolor='black')
|
32 |
+
plt.xlabel('Value')
|
33 |
+
plt.ylabel('Frequency')
|
34 |
+
plt.title('Histogram of Random Samples')
|
35 |
+
st.pyplot(plt)
|
36 |
+
plt.close()
|
37 |
+
else:
|
38 |
+
st.warning("Please generate samp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|