Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
|
| 7 |
+
st.title("Ridge Demo")
|
| 8 |
+
degree = st.slider('Degree', 2, 20, 1)
|
| 9 |
+
x = np.linspace(-1., 1., 100)
|
| 10 |
+
y = 4 + 3*x + 2*np.sin(x) + 2*np.random.randn(len(x))
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
poly = PolynomialFeatures(degree=degree, include_bias=False)
|
| 14 |
+
x_new = poly.fit_transform(x.reshape(-1, 1))
|
| 15 |
+
|
| 16 |
+
lr = LinearRegression()
|
| 17 |
+
lr.fit(x_new, y)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
fig, ax = plt.subplots()
|
| 21 |
+
ax.scatter(x, y)
|
| 22 |
+
y_pred = lr.predict(x_new)
|
| 23 |
+
ax.plot(x, y_pred)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
st.pyplot(fig)
|