File size: 935 Bytes
1fcb538
9131bec
 
1fcb538
96f9a87
 
 
 
 
9131bec
96f9a87
 
 
432ab81
96f9a87
 
 
 
 
 
9131bec
 
96f9a87
 
9131bec
 
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
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt

number_of_observations = st.slider('Number of observations', min_value=50, max_value=150, value=50)
noise_standard_deviation = st.slider('Standard deviation of the noise', min_value = 0.0, max_value=0.5, value=0.25)

np.random.seed(2)

X = np.column_stack((np.ones(number_of_observations), 
                     np.random.random(number_of_observations)))      

w = np.array([3.0, -20.0, 32.0])  # coefficients                                    

X = np.column_stack((X, X[:,1] ** 2))   # add x**2 column
additional_noise = 8 * np.random.binomial(1, 0.03, size = number_of_observations)
y = np.dot(X, w) + noise_standard_deviation * np.random.randn(number_of_observations) \
        + additional_noise	

fig, ax = plt.subplots(dpi=320)
ax.set_xlim((0,1))
ax.set_ylim((-5,20))
ax.scatter(X[:,1], y, c='r', edgecolors='black')

st.pyplot(fig)
st.write(X[:5, :])