JUNGU commited on
Commit
debf26a
Β·
verified Β·
1 Parent(s): 1eb804f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -11
app.py CHANGED
@@ -178,39 +178,70 @@ def plot_correlation_heatmap(data):
178
  st.warning("상관관계 νžˆνŠΈλ§΅μ„ 그릴 수 μžˆλŠ” μˆ«μžν˜• 열이 μ—†μŠ΅λ‹ˆλ‹€.")
179
 
180
  def plot_scatter_with_regression(data, x_var, y_var):
181
- fig = px.scatter(data, x=x_var, y=y_var, color='반' if '반' in data.columns else None)
182
-
183
- # νšŒκ·€μ„  μΆ”κ°€
184
  x = data[x_var]
185
  y = data[y_var]
186
  slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
187
- line_x = np.array([x.min(), x.max()])
188
- line_y = slope * line_x + intercept
189
- fig.add_trace(go.Scatter(x=line_x, y=line_y, mode='lines', name='νšŒκ·€μ„ '))
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  r_squared = r_value ** 2
192
  fig.update_layout(
193
- title=f'{x_var}와 {y_var}의 관계 (R-squared: {r_squared:.4f})',
194
  xaxis_title=x_var,
195
  yaxis_title=y_var,
 
196
  annotations=[
197
  dict(
198
- x=0.5,
199
- y=1.05,
200
  xref='paper',
201
  yref='paper',
202
- text=f'R-squared: {r_squared:.4f}',
203
  showarrow=False,
 
204
  )
205
  ]
206
  )
 
207
  st.plotly_chart(fig)
208
 
209
  # μΆ”κ°€ 톡계 정보
210
  st.write(f"μƒκ΄€κ³„μˆ˜: {r_value:.4f}")
211
  st.write(f"p-value: {p_value:.4f}")
212
  st.write(f"ν‘œμ€€ 였차: {std_err:.4f}")
213
-
214
  def perform_analysis():
215
  if st.session_state.filtered_data is None:
216
  st.session_state.filtered_data = st.session_state.processed_data.copy()
 
178
  st.warning("상관관계 νžˆνŠΈλ§΅μ„ 그릴 수 μžˆλŠ” μˆ«μžν˜• 열이 μ—†μŠ΅λ‹ˆλ‹€.")
179
 
180
  def plot_scatter_with_regression(data, x_var, y_var):
181
+ # νšŒκ·€ 뢄석 μˆ˜ν–‰
 
 
182
  x = data[x_var]
183
  y = data[y_var]
184
  slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
 
 
 
185
 
186
+ # μ˜ˆμΈ‘κ°’ 계산
187
+ y_pred = slope * x + intercept
188
+
189
+ # μž”μ°¨ 계산
190
+ residuals = y - y_pred
191
+
192
+ # κ·Έλž˜ν”„ 생성
193
+ fig = go.Figure()
194
+
195
+ # 산점도 μΆ”κ°€
196
+ fig.add_trace(go.Scatter(
197
+ x=x,
198
+ y=y,
199
+ mode='markers',
200
+ name='Data Points',
201
+ marker=dict(color='blue', size=8),
202
+ error_y=dict(
203
+ type='data',
204
+ array=abs(residuals),
205
+ visible=True
206
+ )
207
+ ))
208
+
209
+ # νšŒκ·€μ„  μΆ”κ°€
210
+ fig.add_trace(go.Scatter(
211
+ x=x,
212
+ y=y_pred,
213
+ mode='lines',
214
+ name='Regression Line',
215
+ line=dict(color='red', width=2)
216
+ ))
217
+
218
+ # λ ˆμ΄μ•„μ›ƒ μ„€μ •
219
  r_squared = r_value ** 2
220
  fig.update_layout(
221
+ title=f'{x_var}와 {y_var}의 관계 (R-squared: {r_squared:.3f})',
222
  xaxis_title=x_var,
223
  yaxis_title=y_var,
224
+ showlegend=True,
225
  annotations=[
226
  dict(
227
+ x=0.05,
228
+ y=0.95,
229
  xref='paper',
230
  yref='paper',
231
+ text=f'y = {slope:.2f}x + {intercept:.2f}\nRΒ² = {r_squared:.3f}',
232
  showarrow=False,
233
+ bgcolor='rgba(255, 255, 255, 0.8)'
234
  )
235
  ]
236
  )
237
+
238
  st.plotly_chart(fig)
239
 
240
  # μΆ”κ°€ 톡계 정보
241
  st.write(f"μƒκ΄€κ³„μˆ˜: {r_value:.4f}")
242
  st.write(f"p-value: {p_value:.4f}")
243
  st.write(f"ν‘œμ€€ 였차: {std_err:.4f}")
244
+
245
  def perform_analysis():
246
  if st.session_state.filtered_data is None:
247
  st.session_state.filtered_data = st.session_state.processed_data.copy()