Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import random
|
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 |
+
st.write("If the plot is not visible, please run the code locally.")
|
47 |
+
st.pyplot(plt.scatter(set1, set2))
|
48 |
+
|
49 |
+
else:
|
50 |
+
st.write(":red[Please specify the number of data points]")
|