Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +21 -9
src/streamlit_app.py
CHANGED
|
@@ -102,7 +102,7 @@ def transform_data(X, y, transformations):
|
|
| 102 |
def plot_residual_analysis(y_true, y_pred, residuals):
|
| 103 |
"""Create comprehensive residual analysis plots"""
|
| 104 |
fig = make_subplots(rows=2, cols=2,
|
| 105 |
-
|
| 106 |
"Q-Q Plot",
|
| 107 |
"Residual Histogram",
|
| 108 |
"Residuals vs Order"))
|
|
@@ -114,16 +114,22 @@ def plot_residual_analysis(y_true, y_pred, residuals):
|
|
| 114 |
)
|
| 115 |
fig.add_hline(y=0, line_dash="dot", row=1, col=1)
|
| 116 |
|
| 117 |
-
# Q-Q Plot
|
| 118 |
-
qq = sm.
|
| 119 |
-
|
|
|
|
|
|
|
| 120 |
fig.add_trace(
|
| 121 |
-
go.Scatter(x=
|
| 122 |
row=1, col=2
|
| 123 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
fig.add_trace(
|
| 125 |
-
go.Scatter(x=
|
| 126 |
-
|
| 127 |
row=1, col=2
|
| 128 |
)
|
| 129 |
|
|
@@ -135,12 +141,18 @@ def plot_residual_analysis(y_true, y_pred, residuals):
|
|
| 135 |
|
| 136 |
# Residuals vs Order
|
| 137 |
fig.add_trace(
|
| 138 |
-
go.Scatter(x=np.arange(len(residuals)), y=residuals,
|
|
|
|
| 139 |
row=2, col=2
|
| 140 |
)
|
| 141 |
fig.add_hline(y=0, line_dash="dot", row=2, col=2)
|
| 142 |
|
| 143 |
-
fig.update_layout(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
st.plotly_chart(fig, use_container_width=True)
|
| 145 |
|
| 146 |
def main():
|
|
|
|
| 102 |
def plot_residual_analysis(y_true, y_pred, residuals):
|
| 103 |
"""Create comprehensive residual analysis plots"""
|
| 104 |
fig = make_subplots(rows=2, cols=2,
|
| 105 |
+
subplot_titles=("Residuals vs Fitted",
|
| 106 |
"Q-Q Plot",
|
| 107 |
"Residual Histogram",
|
| 108 |
"Residuals vs Order"))
|
|
|
|
| 114 |
)
|
| 115 |
fig.add_hline(y=0, line_dash="dot", row=1, col=1)
|
| 116 |
|
| 117 |
+
# Q-Q Plot - Proper implementation
|
| 118 |
+
qq = sm.ProbPlot(residuals)
|
| 119 |
+
theoretical = qq.theoretical_quantiles
|
| 120 |
+
sample = qq.sample_quantiles
|
| 121 |
+
|
| 122 |
fig.add_trace(
|
| 123 |
+
go.Scatter(x=theoretical, y=sample, mode='markers', name='Q-Q Points'),
|
| 124 |
row=1, col=2
|
| 125 |
)
|
| 126 |
+
|
| 127 |
+
# Add reference line
|
| 128 |
+
line_x = np.array([theoretical.min(), theoretical.max()])
|
| 129 |
+
line_y = qq.slope * line_x + qq.intercept
|
| 130 |
fig.add_trace(
|
| 131 |
+
go.Scatter(x=line_x, y=line_y, mode='lines',
|
| 132 |
+
line=dict(color='red'), name='Reference Line'),
|
| 133 |
row=1, col=2
|
| 134 |
)
|
| 135 |
|
|
|
|
| 141 |
|
| 142 |
# Residuals vs Order
|
| 143 |
fig.add_trace(
|
| 144 |
+
go.Scatter(x=np.arange(len(residuals)), y=residuals,
|
| 145 |
+
mode='lines+markers', name='Residuals'),
|
| 146 |
row=2, col=2
|
| 147 |
)
|
| 148 |
fig.add_hline(y=0, line_dash="dot", row=2, col=2)
|
| 149 |
|
| 150 |
+
fig.update_layout(
|
| 151 |
+
height=800,
|
| 152 |
+
showlegend=False,
|
| 153 |
+
template='plotly_white',
|
| 154 |
+
margin=dict(l=50, r=50, b=50, t=50)
|
| 155 |
+
)
|
| 156 |
st.plotly_chart(fig, use_container_width=True)
|
| 157 |
|
| 158 |
def main():
|