Spaces:
Runtime error
Runtime error
Add scatterplot
Browse files
app.py
CHANGED
@@ -2,16 +2,25 @@ import streamlit as st
|
|
2 |
import numpy as np
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
-
number_of_observations = st.slider('Number of observations', min_value=50, max_value=150)
|
|
|
|
|
|
|
|
|
6 |
X = np.column_stack((np.ones(number_of_observations),
|
7 |
-
np.random.random(number_of_observations))
|
8 |
-
|
|
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
11 |
ax.set_xlim((0,1))
|
12 |
ax.set_ylim((-5,20))
|
13 |
-
ax.scatter(X[:,1], y, c='r', edgecolors='
|
14 |
-
|
15 |
-
#line, = ax.plot([], [], lw=line_thickness)
|
16 |
st.pyplot(fig)
|
17 |
st.write(X[:5, :])
|
|
|
2 |
import numpy as np
|
3 |
import matplotlib.pyplot as plt
|
4 |
|
5 |
+
number_of_observations = st.slider('Number of observations', min_value=50, max_value=150, value=50)
|
6 |
+
noise_standard_deviation = st.slider('Standard deviation of the noise', min_value = 0.0, max_value=0.5, value=0.25)
|
7 |
+
|
8 |
+
np.random.seed(2)
|
9 |
+
|
10 |
X = np.column_stack((np.ones(number_of_observations),
|
11 |
+
np.random.random(number_of_observations)))
|
12 |
+
|
13 |
+
w = np.array([3.0, -20.0, 32.0]) # coefficients
|
14 |
|
15 |
+
X = np.column_stack((X, X[:,1] ** 2)) # add x**2 column
|
16 |
+
additional_noise = 8 * np.random.binomial(1, 0.03, size = number_of_observations)
|
17 |
+
y = np.dot(X, w) + noise_standard_deviation * np.random.randn(number_of_observations) \
|
18 |
+
+ additional_noise
|
19 |
+
|
20 |
+
fig, ax = plt.subplots(dpi=320)
|
21 |
ax.set_xlim((0,1))
|
22 |
ax.set_ylim((-5,20))
|
23 |
+
ax.scatter(X[:,1], y, c='r', edgecolors='black')
|
24 |
+
|
|
|
25 |
st.pyplot(fig)
|
26 |
st.write(X[:5, :])
|