File size: 581 Bytes
0e6fe59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures

st.title("Ridge Demo")
degree = st.slider('Degree', 2, 20, 1)
x = np.linspace(-1., 1., 100)
y = 4 + 3*x + 2*np.sin(x) + 2*np.random.randn(len(x))


poly = PolynomialFeatures(degree=degree, include_bias=False)
x_new = poly.fit_transform(x.reshape(-1, 1))

lr = LinearRegression()
lr.fit(x_new, y)


fig, ax = plt.subplots()
ax.scatter(x, y)
y_pred = lr.predict(x_new)
ax.plot(x, y_pred)


st.pyplot(fig)