File size: 1,589 Bytes
e502f76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
import streamlit as st
import numpy as np
import random

# Streamlit app layout
st.title("Analyzing two sets of data")

with st.form("my_form"):
    N = st.number_input("How many data points do you want for each set?", step=1)

    # Button to generate the data
    if st.form_submit_button("Generate Data"):
        # Generate two sets of random data points
        set1 = np.random.normal(loc=10, scale=2, size=N)
        set2 = np.random.normal(loc=12, scale=3, size=N)

    # Display the sets in the app
    # st.write('Set 1:', set1)
    # st.write('Set 2:', set2)

if "set1" in globals():
    mean_set1 = np.mean(set1)
    mean_set2 = np.mean(set2)

    st.subheader("Means")
    st.write(f"Mean of Set 1: {mean_set1:.2f}")
    st.write(f"Mean of Set 2: {mean_set2:.2f}")

    var_set1 = np.var(set1)
    var_set2 = np.var(set2)

    st.subheader("Variances")
    st.write(f"Variance of Set 1: {var_set1:.2f}")
    st.write(f"Variance of Set 2: {var_set2:.2f}")

    cov_set = np.cov(set1, set2)[0, 1]

    st.subheader("Covariance")
    st.write(f"Covariance between Set 1 and Set 2: {cov_set:.2f}")

    # Plotting
    st.subheader("Scatter Plot")
    st.write("Scatter plot of Set 1 against Set 2")
    st.write("You can visualize the relationship between the two sets")
    st.write("Note: This plot requires 'matplotlib' which may not be supported in all Streamlit deployment environments.")
    st.write("If the plot is not visible, please run the code locally.")
    st.pyplot(plt.scatter(set1, set2))
    
else:
    st.write(":red[Please specify the number of data points]")