Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
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.
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
st.write(f"{group1}๊ณผ {group2} ๊ฐ์ ํต๊ณ์ ์ผ๋ก ์ ์ํ ์ฐจ์ด๊ฐ ์์ต๋๋ค.")
|
399 |
-
else:
|
400 |
-
st.write(f"{group1}๊ณผ {group2} ๊ฐ์ ํต๊ณ์ ์ผ๋ก ์ ์ํ ์ฐจ์ด๊ฐ ์์ต๋๋ค.")
|
401 |
else:
|
402 |
-
st.
|
403 |
-
|
404 |
-
|
405 |
elif test_type == "๋์ ํ๋ณธ":
|
406 |
-
|
407 |
-
|
408 |
-
|
|
|
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")
|