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)