Sajid030 commited on
Commit
080b398
ยท
verified ยท
1 Parent(s): f892d45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +111 -112
app.py CHANGED
@@ -110,115 +110,114 @@ if uploaded_file is not None:
110
  if st.button("See Your Feature Details"):
111
  open_dialog()
112
 
113
- if st.button("Generate Plots"):
114
- # Generate the Plots
115
- with st.spinner("Generating Plots.....", show_time= True):
116
- if categorical_ls:
117
- st.header("๐Ÿ“Š Categorical Plots")
118
- # 1. Count Plots
119
- count_plots = []
120
- for x_col in categorical_ls:
121
- if df[x_col].nunique() <= 20:
122
- count_plots.extend(generate_count_plots(df, x_col))
123
-
124
- if count_plots:
125
- st.subheader("Count Plots :-")
126
- st.plotly_chart(combine_figures_as_subplots(count_plots), use_container_width=True)
127
-
128
- # 2. Bar Plots
129
- bar_plots = []
130
- # (Categorical vs Discrete + Continuous)
131
- for x_col in categorical_ls:
132
- if df[x_col].nunique() <= 20:
133
- bar_plots.extend(generate_bar_plots(df, x_col, discrete_ls + continuous_ls))
134
-
135
- if bar_plots:
136
- st.subheader("Bar Plots :-")
137
- st.plotly_chart(combine_figures_as_subplots(bar_plots), use_container_width=True)
138
-
139
- # 3. Grouped Bar Plots
140
- grp_bar_plots = []
141
- # (Categorical vs Discrete + Continuous)
142
- grp_bar_plots.extend(generate_grouped_bar_plots(df, categorical_ls, discrete_ls + continuous_ls))
143
-
144
- if grp_bar_plots:
145
- st.subheader("Grouped Bar Plots :-")
146
- st.plotly_chart(combine_figures_as_subplots(grp_bar_plots), use_container_width=True)
147
-
148
- # 4. Pie Charts
149
- pie_plots = []
150
- for x_col in categorical_ls:
151
- if df[x_col].nunique() <= 20:
152
- pie_plots.extend(generate_pie_plots(df, x_col))
153
-
154
- if pie_plots:
155
- st.subheader("Pie Charts :-")
156
- st.plotly_chart(combine_figures_as_subplots(pie_plots), use_container_width=True)
157
-
158
- if continuous_ls:
159
- st.header("๐Ÿ“Š Numerical Plots")
160
- # 5. Box Plots
161
- box_plots = []
162
- for x_col in categorical_ls:
163
- if df[x_col].nunique() <= 10:
164
- box_plots.extend(generate_box_plots(df, x_col, continuous_ls))
165
-
166
- if box_plots:
167
- st.subheader("Box Plots :-")
168
- st.plotly_chart(combine_figures_as_subplots(box_plots), use_container_width=True)
169
-
170
- # 6. Heat Maps
171
- heat_maps = []
172
- if task == 'Regression':
173
- if categorical_ls:
174
- heat_maps.extend(generate_categorical_correlation_heatmap(df, target_col, categorical_ls))
175
- heat_maps.extend(generate_numeric_correlation_heatmap(df[continuous_ls]))
176
- if heat_maps:
177
- st.subheader("Heat Maps :-")
178
- st.plotly_chart(combine_figures_as_subplots(heat_maps), use_container_width=True)
179
-
180
- # 7. Scatter Plots
181
- if len(continuous_ls) >= 2:
182
- st.subheader("Scatter Plots")
183
- scatter_plots = []
184
- # Creation of unique feature pairs (no repetition like (B, A) if (A, B) is already used)
185
- feature_pairs = []
186
- for i in range(len(continuous_ls)):
187
- for j in range(i + 1, len(continuous_ls)):
188
- feature_pairs.append((continuous_ls[i], continuous_ls[j]))
189
- selection = st.pills("Highlight using a categorical feature :- ", categorical_ls)
190
- scatter_plots.extend(generate_scatter_plots(df, feature_pairs, selection))
191
- if scatter_plots:
192
- st.plotly_chart(combine_figures_as_subplots(scatter_plots), use_container_width=True)
193
-
194
- # 8. Histograms
195
- histograms = []
196
- histograms.extend(generate_histograms(df, continuous_ls))
197
-
198
- if histograms:
199
- st.subheader("Histograms")
200
- st.plotly_chart(combine_figures_as_subplots(histograms), use_container_width=True)
201
-
202
- # 9. Line Plots
203
- line_plots = []
204
- if date_time_ls:
205
- # Extract only date-related components
206
- date_related_keywords = ['_year', '_month', '_day', '_weekday']
207
- date_component_cols = [col for col in extracted_datetime if any(key in col for key in date_related_keywords)]
208
- if date_component_cols:
209
- st.subheader("Line Plots :-")
210
- # Mapping of labels to values
211
- time_grouping_options = {
212
- "Daily": "D",
213
- "Weekly": "W",
214
- "Monthly": "ME",
215
- "Yearly": "YE"
216
- }
217
- time_choice = st.pills("Choose time interval for grouping :- ", list(time_grouping_options.keys()))
218
- # Extract the actual value for resampling
219
- selected_freq = time_grouping_options[time_choice] if time_choice else "ME" # Use default "ME" if no selection
220
- line_plots.extend(generate_line_plots(df, date_component_cols, continuous_ls, selected_freq))
221
-
222
- if line_plots:
223
- st.plotly_chart(combine_figures_as_subplots(line_plots), use_container_width= True)
224
-
 
110
  if st.button("See Your Feature Details"):
111
  open_dialog()
112
 
113
+ # if st.button("Generate Plots"):
114
+ # Generate the Plots
115
+ with st.spinner("Generating Plots.....", show_time= True):
116
+ if categorical_ls:
117
+ st.header("๐Ÿ“Š Categorical Plots")
118
+ # 1. Count Plots
119
+ count_plots = []
120
+ for x_col in categorical_ls:
121
+ if df[x_col].nunique() <= 20:
122
+ count_plots.extend(generate_count_plots(df, x_col))
123
+
124
+ if count_plots:
125
+ st.subheader("Count Plots :-")
126
+ st.plotly_chart(combine_figures_as_subplots(count_plots), use_container_width=True)
127
+
128
+ # 2. Bar Plots
129
+ bar_plots = []
130
+ # (Categorical vs Discrete + Continuous)
131
+ for x_col in categorical_ls:
132
+ if df[x_col].nunique() <= 20:
133
+ bar_plots.extend(generate_bar_plots(df, x_col, discrete_ls + continuous_ls))
134
+
135
+ if bar_plots:
136
+ st.subheader("Bar Plots :-")
137
+ st.plotly_chart(combine_figures_as_subplots(bar_plots), use_container_width=True)
138
+
139
+ # 3. Grouped Bar Plots
140
+ grp_bar_plots = []
141
+ # (Categorical vs Discrete + Continuous)
142
+ grp_bar_plots.extend(generate_grouped_bar_plots(df, categorical_ls, discrete_ls + continuous_ls))
143
+
144
+ if grp_bar_plots:
145
+ st.subheader("Grouped Bar Plots :-")
146
+ st.plotly_chart(combine_figures_as_subplots(grp_bar_plots), use_container_width=True)
147
+
148
+ # 4. Pie Charts
149
+ pie_plots = []
150
+ for x_col in categorical_ls:
151
+ if df[x_col].nunique() <= 20:
152
+ pie_plots.extend(generate_pie_plots(df, x_col))
153
+
154
+ if pie_plots:
155
+ st.subheader("Pie Charts :-")
156
+ st.plotly_chart(combine_figures_as_subplots(pie_plots), use_container_width=True)
157
+
158
+ if continuous_ls:
159
+ st.header("๐Ÿ“Š Numerical Plots")
160
+ # 5. Box Plots
161
+ box_plots = []
162
+ for x_col in categorical_ls:
163
+ if df[x_col].nunique() <= 10:
164
+ box_plots.extend(generate_box_plots(df, x_col, continuous_ls))
165
+
166
+ if box_plots:
167
+ st.subheader("Box Plots :-")
168
+ st.plotly_chart(combine_figures_as_subplots(box_plots), use_container_width=True)
169
+
170
+ # 6. Heat Maps
171
+ heat_maps = []
172
+ if task == 'Regression':
173
+ if categorical_ls:
174
+ heat_maps.extend(generate_categorical_correlation_heatmap(df, target_col, categorical_ls))
175
+ heat_maps.extend(generate_numeric_correlation_heatmap(df[continuous_ls]))
176
+ if heat_maps:
177
+ st.subheader("Heat Maps :-")
178
+ st.plotly_chart(combine_figures_as_subplots(heat_maps), use_container_width=True)
179
+
180
+ # 7. Scatter Plots
181
+ if len(continuous_ls) >= 2:
182
+ st.subheader("Scatter Plots")
183
+ scatter_plots = []
184
+ # Creation of unique feature pairs (no repetition like (B, A) if (A, B) is already used)
185
+ feature_pairs = []
186
+ for i in range(len(continuous_ls)):
187
+ for j in range(i + 1, len(continuous_ls)):
188
+ feature_pairs.append((continuous_ls[i], continuous_ls[j]))
189
+ selection = st.pills("Highlight using a categorical feature :- ", categorical_ls)
190
+ scatter_plots.extend(generate_scatter_plots(df, feature_pairs, selection))
191
+ if scatter_plots:
192
+ st.plotly_chart(combine_figures_as_subplots(scatter_plots), use_container_width=True)
193
+
194
+ # 8. Histograms
195
+ histograms = []
196
+ histograms.extend(generate_histograms(df, continuous_ls))
197
+
198
+ if histograms:
199
+ st.subheader("Histograms")
200
+ st.plotly_chart(combine_figures_as_subplots(histograms), use_container_width=True)
201
+
202
+ # 9. Line Plots
203
+ line_plots = []
204
+ if date_time_ls:
205
+ # Extract only date-related components
206
+ date_related_keywords = ['_year', '_month', '_day', '_weekday']
207
+ date_component_cols = [col for col in extracted_datetime if any(key in col for key in date_related_keywords)]
208
+ if date_component_cols:
209
+ st.subheader("Line Plots :-")
210
+ # Mapping of labels to values
211
+ time_grouping_options = {
212
+ "Daily": "D",
213
+ "Weekly": "W",
214
+ "Monthly": "ME",
215
+ "Yearly": "YE"
216
+ }
217
+ time_choice = st.pills("Choose time interval for grouping :- ", list(time_grouping_options.keys()))
218
+ # Extract the actual value for resampling
219
+ selected_freq = time_grouping_options[time_choice] if time_choice else "ME" # Use default "ME" if no selection
220
+ line_plots.extend(generate_line_plots(df, date_component_cols, continuous_ls, selected_freq))
221
+
222
+ if line_plots:
223
+ st.plotly_chart(combine_figures_as_subplots(line_plots), use_container_width= True)