azarazua commited on
Commit
fdfe2d0
1 Parent(s): 9169168

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -48
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("Analyzing two sets of data")
7
 
8
  with st.form("my_form"):
9
- N = st.number_input("How many data points do you want for each set?", step=1)
10
-
11
- # Button to generate the data
12
- if st.form_submit_button("Generate Data"):
13
- # Generate two sets of random data points
14
- set1 = np.random.normal(loc=10, scale=2, size=N)
15
- set2 = np.random.normal(loc=12, scale=3, size=N)
16
-
17
- # Display the sets in the app
18
- # st.write('Set 1:', set1)
19
- # st.write('Set 2:', set2)
20
-
21
- if "set1" in globals():
22
- mean_set1 = np.mean(set1)
23
- mean_set2 = np.mean(set2)
24
-
25
- st.subheader("Means")
26
- st.write(f"Mean of Set 1: {mean_set1:.2f}")
27
- st.write(f"Mean of Set 2: {mean_set2:.2f}")
28
-
29
- var_set1 = np.var(set1)
30
- var_set2 = np.var(set2)
31
-
32
- st.subheader("Variances")
33
- st.write(f"Variance of Set 1: {var_set1:.2f}")
34
- st.write(f"Variance of Set 2: {var_set2:.2f}")
35
-
36
- cov_set = np.cov(set1, set2)[0, 1]
37
-
38
- st.subheader("Covariance")
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