JUNGU commited on
Commit
8fd3221
ยท
verified ยท
1 Parent(s): f988369

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -50
app.py CHANGED
@@ -314,7 +314,25 @@ def plot_scatter_with_regression(data, x_var, y_var):
314
  st.write(f"์ƒ๊ด€๊ณ„์ˆ˜: {r_value:.4f}")
315
  st.write(f"p-value: {p_value:.4f}")
316
  st.write(f"ํ‘œ์ค€ ์˜ค์ฐจ: {std_err:.4f}")
 
 
 
 
 
 
 
 
 
 
 
 
 
317
 
 
 
 
 
 
318
  def perform_analysis():
319
  if st.session_state.filtered_data is None:
320
  st.session_state.filtered_data = st.session_state.processed_data.copy()
@@ -348,6 +366,9 @@ def perform_analysis():
348
  if x_var and y_var:
349
  plot_scatter_with_regression(st.session_state.filtered_data, x_var, y_var)
350
 
 
 
 
351
  with col3:
352
  st.subheader("ํ†ต๊ณ„์  ๊ฒ€์ •")
353
 
@@ -357,68 +378,50 @@ def perform_analysis():
357
  if st.button("์ •๊ทœ์„ฑ ๊ฒ€์ • ์ˆ˜ํ–‰"):
358
  check_normality(st.session_state.filtered_data, normality_column)
359
 
 
 
 
 
360
  if test_type == "๋…๋ฆฝ ํ‘œ๋ณธ":
361
- # ํ™œ์„ฑํ™”๋œ ์Šฌ๋ผ์ด์„œ์™€ ๊ทธ ์„ ํƒ๋œ ๊ฐ’๋“ค์„ ํ™•์ธ
362
- active_slicers = {}
363
- for col, values in st.session_state.slicers.items():
364
- if values: # ์„ ํƒ๋œ ๊ฐ’์ด ์žˆ๋Š” ๊ฒฝ์šฐ๋งŒ ํฌํ•จ
365
- active_slicers[col] = values
366
-
367
- if active_slicers:
368
- group_column = st.selectbox("๊ทธ๋ฃน ๊ตฌ๋ถ„์„ ์œ„ํ•œ ์—ด ์„ ํƒ:", options=list(active_slicers.keys()))
369
 
370
- # ์„ ํƒ๋œ ๊ทธ๋ฃน ์—ด์˜ ๊ฐ’๋“ค ์ค‘์—์„œ ๋‘ ๊ทธ๋ฃน ์„ ํƒ
371
- available_groups = active_slicers[group_column]
372
- group1 = st.selectbox("์ฒซ ๋ฒˆ์งธ ๊ทธ๋ฃน ์„ ํƒ:", options=available_groups, key="group1")
373
- group2 = st.selectbox("๋‘ ๋ฒˆ์งธ ๊ทธ๋ฃน ์„ ํƒ:",
374
- options=[g for g in available_groups if g != group1],
375
- key="group2")
376
- else:
377
- st.warning("ํ™œ์„ฑํ™”๋œ ์Šฌ๋ผ์ด์„œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ๋จผ์ € ์Šฌ๋ผ์ด์„œ์—์„œ ๊ทธ๋ฃน์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”.")
378
- group_column = None
379
- group1 = None
380
- group2 = None
381
-
382
- value_column = st.selectbox("๋น„๊ตํ•  ๊ฐ’์ด ์žˆ๋Š” ์—ด ์„ ํƒ:", st.session_state.numeric_columns)
383
-
384
- if st.button("๋…๋ฆฝ ํ‘œ๋ณธ T-๊ฒ€์ • ์ˆ˜ํ–‰"):
385
- if group_column and group1 and group2:
386
- # ์„ ํƒ๋œ ๋‘ ๊ทธ๋ฃน์œผ๋กœ ๋ฐ์ดํ„ฐ ํ•„ํ„ฐ๋ง
387
- group1_data = st.session_state.filtered_data[st.session_state.filtered_data[group_column] == group1]
388
- group2_data = st.session_state.filtered_data[st.session_state.filtered_data[group_column] == group2]
389
-
390
- # T-๊ฒ€์ • ์ˆ˜ํ–‰
391
- t_stat, p_value = stats.ttest_ind(group1_data[value_column], group2_data[value_column])
392
 
393
- st.write(f"๋…๋ฆฝ ํ‘œ๋ณธ T-๊ฒ€์ • ๊ฒฐ๊ณผ ({group_column}: {group1} vs {group2}, {value_column} ๋น„๊ต):")
394
- st.write(f"t-ํ†ต๊ณ„๋Ÿ‰: {t_stat:.4f}")
395
- st.write(f"p-value: {p_value:.4f}")
396
-
397
- if p_value < 0.05:
398
- st.write(f"{group1}๊ณผ {group2} ๊ฐ„์— ํ†ต๊ณ„์ ์œผ๋กœ ์œ ์˜ํ•œ ์ฐจ์ด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.")
399
- else:
400
- st.write(f"{group1}๊ณผ {group2} ๊ฐ„์— ํ†ต๊ณ„์ ์œผ๋กœ ์œ ์˜ํ•œ ์ฐจ์ด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.")
401
  else:
402
- st.error("๊ทธ๋ฃน ์„ ํƒ์ด ์™„๋ฃŒ๋˜์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.")
403
-
404
-
405
  elif test_type == "๋Œ€์‘ ํ‘œ๋ณธ":
406
- numeric_columns = st.session_state.numeric_columns
407
- column1 = st.selectbox("์ฒซ ๋ฒˆ์งธ ์—ด ์„ ํƒ:", numeric_columns)
408
- column2 = st.selectbox("๋‘ ๋ฒˆ์งธ ์—ด ์„ ํƒ:", [col for col in numeric_columns if col != column1])
 
409
  if st.button("๋Œ€์‘ ํ‘œ๋ณธ T-๊ฒ€์ • ์ˆ˜ํ–‰"):
410
  perform_paired_ttest(st.session_state.filtered_data, column1, column2)
411
 
412
  elif test_type == "๋‹จ์ผ ํ‘œ๋ณธ":
413
- test_column = st.selectbox("๊ฒ€์ •ํ•  ์—ด ์„ ํƒ:", st.session_state.numeric_columns)
414
- test_value = st.number_input("๊ฒ€์ • ๊ฐ’ ์ž…๋ ฅ:")
415
  if st.button("๋‹จ์ผ ํ‘œ๋ณธ T-๊ฒ€์ • ์ˆ˜ํ–‰"):
416
  perform_onesample_ttest(st.session_state.filtered_data, test_column, test_value)
 
 
 
 
 
417
 
418
- # '๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ๋ถ„์„ํ•˜๊ธฐ' ๋ฒ„ํŠผ ์ถ”๊ฐ€
419
- if st.button("๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ๋ถ„์„ํ•˜๊ธฐ(์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋ฉด ๋‹ค์‹œ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”)"):
420
- reset_session_state()
421
- st.experimental_rerun()
422
  def main():
423
  st.title("๋ชจ๋‘๊ฐ€ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ์ดํ„ฐ ๋ถ„์„ ํˆดํ‚ท Data Analysis for Everyone")
424
  st.link_button("๋งŒ๋“ ์ด ์ฝ”๋‚œ์Œค", "https://www.youtube.com/@conanssam")
 
314
  st.write(f"์ƒ๊ด€๊ณ„์ˆ˜: {r_value:.4f}")
315
  st.write(f"p-value: {p_value:.4f}")
316
  st.write(f"ํ‘œ์ค€ ์˜ค์ฐจ: {std_err:.4f}")
317
+
318
+ def get_active_slicers():
319
+ return {col: values for col, values in st.session_state.slicers.items() if values}
320
+
321
+ def perform_independent_ttest(data, group_column, group1, group2, value_column):
322
+ group1_data = data[data[group_column] == group1][value_column]
323
+ group2_data = data[data[group_column] == group2][value_column]
324
+
325
+ t_stat, p_value = stats.ttest_ind(group1_data, group2_data)
326
+
327
+ st.write(f"๋…๋ฆฝ ํ‘œ๋ณธ T-๊ฒ€์ • ๊ฒฐ๊ณผ ({group_column}: {group1} vs {group2}, {value_column} ๋น„๊ต):")
328
+ st.write(f"t-ํ†ต๊ณ„๋Ÿ‰: {t_stat:.4f}")
329
+ st.write(f"p-value: {p_value:.4f}")
330
 
331
+ if p_value < 0.05:
332
+ st.write(f"{group1}๊ณผ {group2} ๊ฐ„์— ํ†ต๊ณ„์ ์œผ๋กœ ์œ ์˜ํ•œ ์ฐจ์ด๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.")
333
+ else:
334
+ st.write(f"{group1}๊ณผ {group2} ๊ฐ„์— ํ†ต๊ณ„์ ์œผ๋กœ ์œ ์˜ํ•œ ์ฐจ์ด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.")
335
+
336
  def perform_analysis():
337
  if st.session_state.filtered_data is None:
338
  st.session_state.filtered_data = st.session_state.processed_data.copy()
 
366
  if x_var and y_var:
367
  plot_scatter_with_regression(st.session_state.filtered_data, x_var, y_var)
368
 
369
+
370
+
371
+
372
  with col3:
373
  st.subheader("ํ†ต๊ณ„์  ๊ฒ€์ •")
374
 
 
378
  if st.button("์ •๊ทœ์„ฑ ๊ฒ€์ • ์ˆ˜ํ–‰"):
379
  check_normality(st.session_state.filtered_data, normality_column)
380
 
381
+ # T-๊ฒ€์ •
382
+ st.write("T-๊ฒ€์ •")
383
+ test_type = st.radio("T-๊ฒ€์ • ์œ ํ˜• ์„ ํƒ:", ["๋…๋ฆฝ ํ‘œ๋ณธ", "๋Œ€์‘ ํ‘œ๋ณธ", "๋‹จ์ผ ํ‘œ๋ณธ"], key="test_type_radio")
384
+
385
  if test_type == "๋…๋ฆฝ ํ‘œ๋ณธ":
386
+ active_slicers = get_active_slicers()
 
 
 
 
 
 
 
387
 
388
+ if active_slicers:
389
+ group_column = st.selectbox("๊ทธ๋ฃน ๊ตฌ๋ถ„์„ ์œ„ํ•œ ์—ด ์„ ํƒ:", options=list(active_slicers.keys()))
390
+ available_groups = active_slicers[group_column]
391
+ group1 = st.selectbox("์ฒซ ๋ฒˆ์งธ ๊ทธ๋ฃน ์„ ํƒ:", options=available_groups, key="group1")
392
+ group2 = st.selectbox("๋‘ ๋ฒˆ์งธ ๊ทธ๋ฃน ์„ ํƒ:",
393
+ options=[g for g in available_groups if g != group1],
394
+ key="group2")
395
+ value_column = st.selectbox("๋น„๊ตํ•  ๊ฐ’์ด ์žˆ๋Š” ์—ด ์„ ํƒ:", st.session_state.numeric_columns)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
 
397
+ if st.button("๋…๋ฆฝ ํ‘œ๋ณธ T-๊ฒ€์ • ์ˆ˜ํ–‰"):
398
+ if group1 and group2:
399
+ perform_independent_ttest(st.session_state.filtered_data, group_column, group1, group2, value_column)
400
+ else:
401
+ st.error("๋‘ ๊ฐœ์˜ ์„œ๋กœ ๋‹ค๋ฅธ ๊ทธ๋ฃน์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”.")
 
 
 
402
  else:
403
+ st.warning("ํ™œ์„ฑํ™”๋œ ์Šฌ๋ผ์ด์„œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. ๋จผ์ € ์Šฌ๋ผ์ด์„œ์—์„œ ๊ทธ๋ฃน์„ ์„ ํƒํ•ด์ฃผ์„ธ์š”.")
404
+
 
405
  elif test_type == "๋Œ€์‘ ํ‘œ๋ณธ":
406
+ column1 = st.selectbox("์ฒซ ๋ฒˆ์งธ ์—ด ์„ ํƒ:", st.session_state.numeric_columns, key="paired_col1")
407
+ column2 = st.selectbox("๋‘ ๋ฒˆ์งธ ์—ด ์„ ํƒ:",
408
+ [col for col in st.session_state.numeric_columns if col != column1],
409
+ key="paired_col2")
410
  if st.button("๋Œ€์‘ ํ‘œ๋ณธ T-๊ฒ€์ • ์ˆ˜ํ–‰"):
411
  perform_paired_ttest(st.session_state.filtered_data, column1, column2)
412
 
413
  elif test_type == "๋‹จ์ผ ํ‘œ๋ณธ":
414
+ test_column = st.selectbox("๊ฒ€์ •ํ•  ์—ด ์„ ํƒ:", st.session_state.numeric_columns, key="one_sample_col")
415
+ test_value = st.number_input("๊ฒ€์ • ๊ฐ’ ์ž…๋ ฅ:", key="one_sample_value")
416
  if st.button("๋‹จ์ผ ํ‘œ๋ณธ T-๊ฒ€์ • ์ˆ˜ํ–‰"):
417
  perform_onesample_ttest(st.session_state.filtered_data, test_column, test_value)
418
+
419
+ # '๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ๋ถ„์„ํ•˜๊ธฐ' ๋ฒ„ํŠผ ์ถ”๊ฐ€
420
+ if st.button("๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ ๋ถ„์„ํ•˜๊ธฐ(์˜ค๋ฅ˜๊ฐ€ ๋‚˜๋ฉด ๋‹ค์‹œ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”)"):
421
+ reset_session_state()
422
+ st.experimental_rerun()
423
 
424
+ ## ๋ฉ”์ธ
 
 
 
425
  def main():
426
  st.title("๋ชจ๋‘๊ฐ€ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐ์ดํ„ฐ ๋ถ„์„ ํˆดํ‚ท Data Analysis for Everyone")
427
  st.link_button("๋งŒ๋“ ์ด ์ฝ”๋‚œ์Œค", "https://www.youtube.com/@conanssam")