Spaces:
Sleeping
Sleeping
File size: 4,370 Bytes
ff27984 68fece7 ff27984 68fece7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy.stats import norm, skew
import platform
# ํ๊ธ ํฐํธ ์ค์ (Windows, Mac, Linux ํ๊ฒฝ์ ๋ง๊ฒ ์๋ ์ค์ )
if platform.system() == 'Windows':
plt.rc('font', family='Malgun Gothic')
elif platform.system() == 'Darwin': # Mac
plt.rc('font', family='AppleGothic')
else: # Linux
# ๋๋๊ณ ๋ ํฐํธ๊ฐ ์ค์น๋์ด ์์ด์ผ ํฉ๋๋ค.
# sudo apt-get install fonts-nanum*
plt.rc('font', family='NanumGothic')
plt.rcParams['axes.unicode_minus'] = False # ๋ง์ด๋์ค ํฐํธ ๊นจ์ง ๋ฐฉ์ง
def main():
"""
์คํธ๋ฆผ๋ฆฟ์ ์ด์ฉํ ํ์ ์ ์ ๋ถํฌ ๋ถ์ ์ ํ๋ฆฌ์ผ์ด์
"""
st.title("ํ์ ์ ์ ๋ถํฌ ๋ถ์ ๋๊ตฌ ๐")
st.write("CSV ํ์ผ์ ์
๋ก๋ํ์ฌ ํ์๋ค์ ์ ์ ๋ถํฌ๋ฅผ ํ์ธํ๊ณ , ์ ๊ท๋ถํฌ์์ ์ฐจ์ด ๋ฐ ์๋(skewness)๋ฅผ ๋ถ์ํฉ๋๋ค.")
st.write("---")
# ํ์ผ ์
๋ก๋ ์์ ฏ
uploaded_file = st.file_uploader("์ ์ ๋ฐ์ดํฐ๊ฐ ํฌํจ๋ CSV ํ์ผ์ ์
๋ก๋ํ์ธ์.", type="csv")
if uploaded_file is not None:
try:
# utf-8-sig ์ธ์ฝ๋ฉ์ผ๋ก CSV ํ์ผ ์ฝ๊ธฐ
df = pd.read_csv(uploaded_file, encoding='utf-8-sig')
st.subheader("์
๋ก๋๋ ๋ฐ์ดํฐ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
st.dataframe(df.head())
# ๋ถ์ํ ์ ์ ์ด ์ ํ
score_column = st.selectbox("๋ถ์ํ ์ ์ ์ด(column)์ ์ ํํ์ธ์:", df.columns)
if score_column:
# ์ ํ๋ ์ด์ ๋ฐ์ดํฐ ์ถ์ถ (๊ฒฐ์ธก์น ์ ๊ฑฐ)
scores = df[score_column].dropna()
if pd.api.types.is_numeric_dtype(scores):
st.subheader(f"'{score_column}' ์ ์ ๋ถํฌ ๋ถ์ ๊ฒฐ๊ณผ")
# 1. ๊ธฐ์ ํต๊ณ๋ ํ์
st.write("#### ๐ ๊ธฐ์ ํต๊ณ๋")
st.table(scores.describe())
# 2. ๋ถํฌ ์๊ฐํ ๋ฐ ์ ๊ท๋ถํฌ ๋น๊ต
st.write("#### ๐จ ์ ์ ๋ถํฌ ์๊ฐํ")
fig, ax = plt.subplots(figsize=(10, 6))
# ํ์คํ ๊ทธ๋จ ๋ฐ KDE ํ๋กฏ
sns.histplot(scores, kde=True, stat='density', label='ํ์ ์ ์ ๋ถํฌ', ax=ax)
# ์ ๊ท๋ถํฌ ๊ณก์ ์ถ๊ฐ
mu, std = norm.fit(scores)
xmin, xmax = plt.xlim()
x = np.linspace(xmin, xmax, 100)
p = norm.pdf(x, mu, std)
ax.plot(x, p, 'k', linewidth=2, label='์ ๊ท๋ถํฌ ๊ณก์ ')
title = f"'{score_column}' ์ ์ ๋ถํฌ (ํ๊ท : {mu:.2f}, ํ์คํธ์ฐจ: {std:.2f})"
ax.set_title(title)
ax.set_xlabel('์ ์')
ax.set_ylabel('๋ฐ๋')
ax.legend()
st.pyplot(fig)
# 3. ์๋(Skewness) ๊ณ์ฐ ๋ฐ ํด์
st.write("#### ๐ ์๋ (Skewness) ๋ถ์")
skewness = skew(scores)
st.metric(label="์๋ (Skewness)", value=f"{skewness:.4f}")
if skewness > 0.5:
st.info("๊ผฌ๋ฆฌ๊ฐ ์ค๋ฅธ์ชฝ์ผ๋ก ๊ธด ๋ถํฌ (Positive Skew): ๋๋ถ๋ถ์ ํ์๋ค์ด ํ๊ท ๋ณด๋ค ๋ฎ์ ์ ์์ ๋ชฐ๋ ค์๊ณ , ์ผ๋ถ ํ์๋ค์ด ๋งค์ฐ ๋์ ์ ์๋ฅผ ๋ฐ์์ต๋๋ค.")
elif skewness < -0.5:
st.info("๊ผฌ๋ฆฌ๊ฐ ์ผ์ชฝ์ผ๋ก ๊ธด ๋ถํฌ (Negative Skew): ๋๋ถ๋ถ์ ํ์๋ค์ด ํ๊ท ๋ณด๋ค ๋์ ์ ์์ ๋ชฐ๋ ค์๊ณ , ์ผ๋ถ ํ์๋ค์ด ๋งค์ฐ ๋ฎ์ ์ ์๋ฅผ ๋ฐ์์ต๋๋ค.")
else:
st.info("๋์นญ์ ๊ฐ๊น์ด ๋ถํฌ: ์ ์๊ฐ ํ๊ท ์ ์ค์ฌ์ผ๋ก ๋น๊ต์ ๊ณ ๋ฅด๊ฒ ๋ถํฌ๋์ด ์์ต๋๋ค.")
else:
st.error(f"์ค๋ฅ: ์ ํํ์ '{score_column}' ์ด์ ์ซ์ ๋ฐ์ดํฐ๊ฐ ์๋๋๋ค. ์ซ์ ๋ฐ์ดํฐ๋ก ๊ตฌ์ฑ๋ ์ด์ ์ ํํด์ฃผ์ธ์.")
except Exception as e:
st.error(f"ํ์ผ์ ์ฝ๋ ๋์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {e}")
st.warning("CSV ํ์ผ์ด 'utf-8-sig' ๋๋ 'utf-8' ์ธ์ฝ๋ฉ ํ์์ธ์ง ํ์ธํด์ฃผ์ธ์.")
if __name__ == '__main__':
main() |