Nipun commited on
Commit
9c327fd
·
1 Parent(s): d35a4f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -16
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import streamlit as st
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
- from sklearn.linear_model import LinearRegression
5
  from sklearn.preprocessing import PolynomialFeatures
6
  from sklearn.metrics import mean_squared_error
7
 
@@ -9,7 +9,7 @@ st.title("Ridge Demo")
9
  col1, col2 = st.columns(2)
10
 
11
  degree = st.slider('Degree', 2, 40, 1)
12
- lambda_ = st.slider('Lambda (Regularisation)', 0, 500, 1)
13
 
14
 
15
  with col1:
@@ -27,31 +27,45 @@ x_new = poly.fit_transform(x.reshape(-1, 1))
27
 
28
  lr = LinearRegression()
29
  lr.fit(x_new, y)
 
30
 
31
 
32
- fig, ax = plt.subplots()
33
- ax.scatter(x, y)
34
- y_pred = lr.predict(x_new)
35
- ax.plot(x, y_pred)
 
 
 
36
 
37
- ax.spines['right'].set_visible(False)
38
- ax.spines['top'].set_visible(False)
39
 
40
- # Only show ticks on the left and bottom spines
41
- ax.yaxis.set_ticks_position('left')
42
- ax.xaxis.set_ticks_position('bottom')
43
 
44
- ax.set_xlabel("x")
45
- ax.set_ylabel("y")
 
 
 
 
 
 
 
 
46
 
47
  rmse = np.round(np.sqrt(mean_squared_error(y_pred, y)), 2)
48
- ax.set_title(f"Train RMSE: {rmse}")
 
 
 
49
 
50
  with col1:
51
- st.pyplot(fig)
52
 
53
  with col2:
54
- st.pyplot(fig)
55
  hide_streamlit_style = """
56
  <style>
57
  #MainMenu {visibility: hidden;}
 
1
  import streamlit as st
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
+ from sklearn.linear_model import LinearRegression, Ridge
5
  from sklearn.preprocessing import PolynomialFeatures
6
  from sklearn.metrics import mean_squared_error
7
 
 
9
  col1, col2 = st.columns(2)
10
 
11
  degree = st.slider('Degree', 2, 40, 1)
12
+ alpha = st.slider('Lambda (Regularisation)', 0, 500, 1)
13
 
14
 
15
  with col1:
 
27
 
28
  lr = LinearRegression()
29
  lr.fit(x_new, y)
30
+ y_pred = lr.predict(x_new)
31
 
32
 
33
+ ri = Ridge(alpha = alpha)
34
+ ri.fit(x_new, y)
35
+ y_pred_ri = ri.predict(x_new)
36
+
37
+
38
+ fig1, ax1 = plt.subplots()
39
+ fig2, ax2 = plt.subplots()
40
 
41
+ ax1.scatter(x, y)
42
+ ax1.plot(x, y_pred)
43
 
44
+ ax2.scatter(x, y)
45
+ ax2.plot(x, y_pred_ri)
 
46
 
47
+ for ax in [ax1, ax2]:
48
+ ax.spines['right'].set_visible(False)
49
+ ax.spines['top'].set_visible(False)
50
+
51
+ # Only show ticks on the left and bottom spines
52
+ ax.yaxis.set_ticks_position('left')
53
+ ax.xaxis.set_ticks_position('bottom')
54
+
55
+ ax.set_xlabel("x")
56
+ ax.set_ylabel("y")
57
 
58
  rmse = np.round(np.sqrt(mean_squared_error(y_pred, y)), 2)
59
+ ax1.set_title(f"Train RMSE: {rmse}")
60
+
61
+ rmse_ri = np.round(np.sqrt(mean_squared_error(y_pred_ri, y)), 2)
62
+ ax2.set_title(f"Train RMSE: {rmse_ri}")
63
 
64
  with col1:
65
+ st.pyplot(fig1)
66
 
67
  with col2:
68
+ st.pyplot(fig2)
69
  hide_streamlit_style = """
70
  <style>
71
  #MainMenu {visibility: hidden;}