Spaces:
Running
Running
Update app/pages/week_1.py
Browse files- app/pages/week_1.py +74 -1
app/pages/week_1.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
|
3 |
def show_week_content():
|
4 |
st.markdown("""
|
@@ -38,8 +41,78 @@ def show_week_content():
|
|
38 |
if submitted:
|
39 |
st.success("Topic submitted successfully! We'll review and provide feedback.")
|
40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
# Literature Review Section
|
42 |
-
st.header("
|
43 |
st.markdown("""
|
44 |
### Steps for Conducting Literature Review:
|
45 |
1. Search for relevant papers
|
|
|
1 |
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import plotly.graph_objects as go
|
4 |
+
from sklearn.linear_model import LinearRegression
|
5 |
|
6 |
def show_week_content():
|
7 |
st.markdown("""
|
|
|
41 |
if submitted:
|
42 |
st.success("Topic submitted successfully! We'll review and provide feedback.")
|
43 |
|
44 |
+
# Linear Regression Visualization
|
45 |
+
st.header("2. Linear Regression Demo")
|
46 |
+
st.markdown("""
|
47 |
+
### Understanding Linear Regression
|
48 |
+
|
49 |
+
Linear regression is a fundamental machine learning algorithm that models the relationship between a dependent variable and one or more independent variables.
|
50 |
+
Below is an interactive demonstration of simple linear regression.
|
51 |
+
""")
|
52 |
+
|
53 |
+
# Create interactive controls
|
54 |
+
col1, col2 = st.columns(2)
|
55 |
+
with col1:
|
56 |
+
n_points = st.slider("Number of data points", 10, 100, 50)
|
57 |
+
noise = st.slider("Noise level", 0.1, 2.0, 0.5)
|
58 |
+
with col2:
|
59 |
+
slope = st.slider("True slope", -2.0, 2.0, 1.0)
|
60 |
+
intercept = st.slider("True intercept", -5.0, 5.0, 0.0)
|
61 |
+
|
62 |
+
# Generate synthetic data
|
63 |
+
np.random.seed(42)
|
64 |
+
X = np.random.rand(n_points) * 10
|
65 |
+
y = slope * X + intercept + np.random.normal(0, noise, n_points)
|
66 |
+
|
67 |
+
# Fit linear regression
|
68 |
+
X_reshaped = X.reshape(-1, 1)
|
69 |
+
model = LinearRegression()
|
70 |
+
model.fit(X_reshaped, y)
|
71 |
+
y_pred = model.predict(X_reshaped)
|
72 |
+
|
73 |
+
# Create the plot
|
74 |
+
fig = go.Figure()
|
75 |
+
|
76 |
+
# Add scatter plot of actual data
|
77 |
+
fig.add_trace(go.Scatter(
|
78 |
+
x=X,
|
79 |
+
y=y,
|
80 |
+
mode='markers',
|
81 |
+
name='Actual Data',
|
82 |
+
marker=dict(color='blue')
|
83 |
+
))
|
84 |
+
|
85 |
+
# Add regression line
|
86 |
+
fig.add_trace(go.Scatter(
|
87 |
+
x=X,
|
88 |
+
y=y_pred,
|
89 |
+
mode='lines',
|
90 |
+
name='Regression Line',
|
91 |
+
line=dict(color='red')
|
92 |
+
))
|
93 |
+
|
94 |
+
# Update layout
|
95 |
+
fig.update_layout(
|
96 |
+
title='Linear Regression Visualization',
|
97 |
+
xaxis_title='X',
|
98 |
+
yaxis_title='Y',
|
99 |
+
showlegend=True,
|
100 |
+
height=500
|
101 |
+
)
|
102 |
+
|
103 |
+
# Display the plot
|
104 |
+
st.plotly_chart(fig, use_container_width=True)
|
105 |
+
|
106 |
+
# Display regression coefficients
|
107 |
+
st.markdown(f"""
|
108 |
+
### Regression Results
|
109 |
+
- Estimated slope: {model.coef_[0]:.2f}
|
110 |
+
- Estimated intercept: {model.intercept_:.2f}
|
111 |
+
- R² score: {model.score(X_reshaped, y):.2f}
|
112 |
+
""")
|
113 |
+
|
114 |
# Literature Review Section
|
115 |
+
st.header("3. Literature Review")
|
116 |
st.markdown("""
|
117 |
### Steps for Conducting Literature Review:
|
118 |
1. Search for relevant papers
|