JUNGU commited on
Commit
23711c4
ยท
verified ยท
1 Parent(s): 1d927a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +110 -27
app.py CHANGED
@@ -5,8 +5,8 @@ import plotly.express as px
5
  import plotly.graph_objects as go
6
  from io import StringIO
7
  import openpyxl
8
- import matplotlib.pyplot as plt
9
  import matplotlib.font_manager as fm
 
10
 
11
  # ํ•œ๊ธ€ ํฐํŠธ ์„ค์ •
12
  def set_font():
@@ -89,38 +89,121 @@ def perform_analysis(data):
89
  else:
90
  st.write("์ƒ๊ด€๊ด€๊ณ„ ํžˆํŠธ๋งต์„ ๊ทธ๋ฆด ์ˆ˜ ์žˆ๋Š” ์ˆซ์žํ˜• ์—ด์ด ์—†์Šต๋‹ˆ๋‹ค.")
91
 
92
- # ์‚ฐ์ ๋„ ํ–‰๋ ฌ
93
- st.write("์‚ฐ์ ๋„ ํ–‰๋ ฌ:")
94
- if not numeric_data.empty:
95
- fig = px.scatter_matrix(numeric_data)
96
- fig.update_layout(title='์‚ฐ์ ๋„ ํ–‰๋ ฌ')
97
  st.plotly_chart(fig)
98
- else:
99
- st.write("์‚ฐ์ ๋„ ํ–‰๋ ฌ์„ ๊ทธ๋ฆด ์ˆ˜ ์žˆ๋Š” ์ˆซ์žํ˜• ์—ด์ด ์—†์Šต๋‹ˆ๋‹ค.")
100
 
101
- # ํžˆ์Šคํ† ๊ทธ๋žจ
102
- st.write("ํžˆ์Šคํ† ๊ทธ๋žจ:")
103
- for column in numeric_data.columns:
104
- fig = px.histogram(data, x=column, marginal='box')
105
- fig.update_layout(title=f'{column} ํžˆ์Šคํ† ๊ทธ๋žจ')
106
  st.plotly_chart(fig)
107
 
108
- # ๋ฐ•์Šคํ”Œ๋กฏ
109
- st.write("๋ฐ•์Šคํ”Œ๋กฏ:")
110
- for column in numeric_data.columns:
111
- fig = px.box(data, y=column)
112
- fig.update_layout(title=f'{column} ๋ฐ•์Šคํ”Œ๋กฏ')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  st.plotly_chart(fig)
114
 
115
- # ๋ฒ”์ฃผํ˜• ๋ณ€์ˆ˜ ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„
116
- categorical_columns = data.select_dtypes(include=['object']).columns
117
- if not categorical_columns.empty:
118
- st.write("๋ฒ”์ฃผํ˜• ๋ณ€์ˆ˜ ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„:")
119
- for column in categorical_columns:
120
- value_counts = data[column].value_counts().reset_index()
121
- value_counts.columns = ['category', 'count']
122
- fig = px.bar(value_counts, x='category', y='count', title=f'{column} ๋ถ„ํฌ')
123
- fig.update_layout(xaxis_title=column, yaxis_title='๊ฐœ์ˆ˜')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  st.plotly_chart(fig)
125
 
126
  def main():
 
5
  import plotly.graph_objects as go
6
  from io import StringIO
7
  import openpyxl
 
8
  import matplotlib.font_manager as fm
9
+ from scipy import stats
10
 
11
  # ํ•œ๊ธ€ ํฐํŠธ ์„ค์ •
12
  def set_font():
 
89
  else:
90
  st.write("์ƒ๊ด€๊ด€๊ณ„ ํžˆํŠธ๋งต์„ ๊ทธ๋ฆด ์ˆ˜ ์žˆ๋Š” ์ˆซ์žํ˜• ์—ด์ด ์—†์Šต๋‹ˆ๋‹ค.")
91
 
92
+ # ๊ณผ๋ชฉ๋ณ„ ์ ์ˆ˜ ๋ถ„ํฌ
93
+ if '๊ณผ๋ชฉ' in data.columns and 'ํ•™์Šตํ‰๊ฐ€' in data.columns:
94
+ st.write("๊ณผ๋ชฉ๋ณ„ ์ ์ˆ˜ ๋ถ„ํฌ:")
95
+ fig = px.box(data, x='๊ณผ๋ชฉ', y='ํ•™์Šตํ‰๊ฐ€', points="all")
96
+ fig.update_layout(title='๊ณผ๋ชฉ๋ณ„ ํ•™์Šตํ‰๊ฐ€ ์ ์ˆ˜ ๋ถ„ํฌ')
97
  st.plotly_chart(fig)
 
 
98
 
99
+ # ์›”๋ณ„ ์ ์ˆ˜ ์ถ”์ด
100
+ if '๋‹ฌ' in data.columns and 'ํ•™์Šตํ‰๊ฐ€' in data.columns:
101
+ st.write("์›”๋ณ„ ์ ์ˆ˜ ์ถ”์ด:")
102
+ fig = px.line(data, x='๋‹ฌ', y='ํ•™์Šตํ‰๊ฐ€', color='๊ณผ๋ชฉ', markers=True)
103
+ fig.update_layout(title='์›”๋ณ„ ํ•™์Šตํ‰๊ฐ€ ์ ์ˆ˜ ์ถ”์ด')
104
  st.plotly_chart(fig)
105
 
106
+ # ์ž๊ธฐ๋…ธ๋ ฅ๋„์™€ ํ•™์Šตํ‰๊ฐ€ ๊ด€๊ณ„ (ํšŒ๊ท€์„ ๊ณผ R-squared ์ถ”๊ฐ€)
107
+ if '์ž๊ธฐ๋…ธ๋ ฅ๋„' in data.columns and 'ํ•™์Šตํ‰๊ฐ€' in data.columns:
108
+ st.write("์ž๊ธฐ๋…ธ๋ ฅ๋„์™€ ํ•™์Šตํ‰๊ฐ€ ๊ด€๊ณ„:")
109
+ fig = px.scatter(data, x='์ž๊ธฐ๋…ธ๋ ฅ๋„', y='ํ•™์Šตํ‰๊ฐ€', color='๊ณผ๋ชฉ', hover_data=['๋‹ฌ'])
110
+
111
+ # ์ „์ฒด ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ํšŒ๊ท€์„  ์ถ”๊ฐ€
112
+ x = data['์ž๊ธฐ๋…ธ๋ ฅ๋„']
113
+ y = data['ํ•™์Šตํ‰๊ฐ€']
114
+ slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
115
+ line_x = np.array([x.min(), x.max()])
116
+ line_y = slope * line_x + intercept
117
+ fig.add_trace(go.Scatter(x=line_x, y=line_y, mode='lines', name='ํšŒ๊ท€์„ '))
118
+
119
+ r_squared = r_value ** 2
120
+ fig.update_layout(
121
+ title=f'์ž๊ธฐ๋…ธ๋ ฅ๋„์™€ ํ•™์Šตํ‰๊ฐ€ ๊ด€๊ณ„ (R-squared: {r_squared:.4f})',
122
+ annotations=[
123
+ dict(
124
+ x=0.5,
125
+ y=1.05,
126
+ xref='paper',
127
+ yref='paper',
128
+ text=f'R-squared: {r_squared:.4f}',
129
+ showarrow=False,
130
+ )
131
+ ]
132
+ )
133
  st.plotly_chart(fig)
134
 
135
+ # ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ ํ•„ํ„ฐ๋ง
136
+ st.write("์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ ํ•„ํ„ฐ๋ง:")
137
+ if '์ž๊ธฐ๋…ธ๋ ฅ๋„' in data.columns:
138
+ min_effort = int(data['์ž๊ธฐ๋…ธ๋ ฅ๋„'].min())
139
+ max_effort = int(data['์ž๊ธฐ๋…ธ๋ ฅ๋„'].max())
140
+ effort_range = st.slider("์ž๊ธฐ๋…ธ๋ ฅ๋„ ๋ฒ”์œ„ ์„ ํƒ", min_effort, max_effort, (min_effort, max_effort))
141
+
142
+ filtered_data = data[(data['์ž๊ธฐ๋…ธ๋ ฅ๋„'] >= effort_range[0]) & (data['์ž๊ธฐ๋…ธ๋ ฅ๋„'] <= effort_range[1])]
143
+
144
+ if '๊ณผ๋ชฉ' in filtered_data.columns and 'ํ•™์Šตํ‰๊ฐ€' in filtered_data.columns:
145
+ fig = px.scatter(filtered_data, x='์ž๊ธฐ๋…ธ๋ ฅ๋„', y='ํ•™์Šตํ‰๊ฐ€', color='๊ณผ๋ชฉ', hover_data=['๋‹ฌ'])
146
+
147
+ # ํ•„ํ„ฐ๋ง๋œ ๋ฐ์ดํ„ฐ์— ๋Œ€ํ•œ ํšŒ๊ท€์„  ์ถ”๊ฐ€
148
+ x = filtered_data['์ž๊ธฐ๋…ธ๋ ฅ๋„']
149
+ y = filtered_data['ํ•™์Šตํ‰๊ฐ€']
150
+ slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
151
+ line_x = np.array([x.min(), x.max()])
152
+ line_y = slope * line_x + intercept
153
+ fig.add_trace(go.Scatter(x=line_x, y=line_y, mode='lines', name='ํšŒ๊ท€์„ '))
154
+
155
+ r_squared = r_value ** 2
156
+ fig.update_layout(
157
+ title=f'์ž๊ธฐ๋…ธ๋ ฅ๋„ {effort_range[0]}-{effort_range[1]} ๋ฒ”์œ„์˜ ํ•™์Šตํ‰๊ฐ€ ๊ด€๊ณ„ (R-squared: {r_squared:.4f})',
158
+ annotations=[
159
+ dict(
160
+ x=0.5,
161
+ y=1.05,
162
+ xref='paper',
163
+ yref='paper',
164
+ text=f'R-squared: {r_squared:.4f}',
165
+ showarrow=False,
166
+ )
167
+ ]
168
+ )
169
+ st.plotly_chart(fig)
170
+
171
+ # ๊ณผ๋ชฉ๋ณ„ ์ƒ์„ธ ๋ถ„์„
172
+ if '๊ณผ๋ชฉ' in data.columns:
173
+ st.write("๊ณผ๋ชฉ๋ณ„ ์ƒ์„ธ ๋ถ„์„:")
174
+ selected_subject = st.selectbox("๋ถ„์„ํ•  ๊ณผ๋ชฉ ์„ ํƒ", data['๊ณผ๋ชฉ'].unique())
175
+ subject_data = data[data['๊ณผ๋ชฉ'] == selected_subject]
176
+
177
+ if '๋‹ฌ' in subject_data.columns and 'ํ•™์Šตํ‰๊ฐ€' in subject_data.columns:
178
+ fig = px.line(subject_data, x='๋‹ฌ', y='ํ•™์Šตํ‰๊ฐ€', markers=True)
179
+ fig.update_layout(title=f'{selected_subject} ์›”๋ณ„ ํ•™์Šตํ‰๊ฐ€ ์ ์ˆ˜ ์ถ”์ด')
180
+ st.plotly_chart(fig)
181
+
182
+ if '์ž๊ธฐ๋…ธ๋ ฅ๋„' in subject_data.columns and 'ํ•™์Šตํ‰๊ฐ€' in subject_data.columns:
183
+ fig = px.scatter(subject_data, x='์ž๊ธฐ๋…ธ๋ ฅ๋„', y='ํ•™์Šตํ‰๊ฐ€', hover_data=['๋‹ฌ'])
184
+
185
+ # ์„ ํƒ๋œ ๊ณผ๋ชฉ์— ๋Œ€ํ•œ ํšŒ๊ท€์„  ์ถ”๊ฐ€
186
+ x = subject_data['์ž๊ธฐ๋…ธ๋ ฅ๋„']
187
+ y = subject_data['ํ•™์Šตํ‰๊ฐ€']
188
+ slope, intercept, r_value, p_value, std_err = stats.linregress(x, y)
189
+ line_x = np.array([x.min(), x.max()])
190
+ line_y = slope * line_x + intercept
191
+ fig.add_trace(go.Scatter(x=line_x, y=line_y, mode='lines', name='ํšŒ๊ท€์„ '))
192
+
193
+ r_squared = r_value ** 2
194
+ fig.update_layout(
195
+ title=f'{selected_subject} ์ž๊ธฐ๋…ธ๋ ฅ๋„์™€ ํ•™์Šตํ‰๊ฐ€ ๊ด€๊ณ„ (R-squared: {r_squared:.4f})',
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
  def main():