Mattral commited on
Commit
8bb6881
·
verified ·
1 Parent(s): 6746f85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -25
app.py CHANGED
@@ -418,19 +418,6 @@ df.drop(columns={col_to_delete}, inplace=True)
418
  st.pyplot(fig)
419
  new_line()
420
 
421
- # Feature Importance (Only if a model has been trained)
422
- if 'trained_model' in st.session_state and st.session_state.trained_model is not None:
423
- feature_importance = st.checkbox("Show Feature Importance (Only click after training or it will throw error)", value=False)
424
- new_line()
425
- if feature_importance:
426
- model = st.session_state.trained_model
427
- importances = pd.Series(model.feature_importances_, index=X_train.columns)
428
- fig, ax = plt.subplots()
429
- importances.sort_values().plot(kind='barh', ax=ax)
430
- ax.set_title('Feature Importance')
431
- st.pyplot(fig)
432
- new_line()
433
-
434
  new_line()
435
  if st.checkbox("Identify Outliers", value=False):
436
  numeric_cols = df.select_dtypes(include=np.number).columns.tolist()
@@ -479,20 +466,26 @@ df.drop(columns={col_to_delete}, inplace=True)
479
 
480
  new_line()
481
  if st.checkbox("Show Word Cloud", value=False):
482
- text_col = st.selectbox("Select Text Column for Word Cloud", options=df.select_dtypes(include=[np.object]).columns.tolist())
483
- text_data = ' '.join(df[text_col].dropna()).strip() # Collect and strip the text data
484
 
485
- if not text_col and text_data:
486
- st.error("No words available to create a word cloud.")
487
- elif text_data: # Check if there is any text data
488
- wordcloud = WordCloud(width=800, height=400).generate(text_data)
489
- fig, ax = plt.subplots()
490
- ax.imshow(wordcloud, interpolation='bilinear')
491
- ax.axis('off')
492
- st.pyplot(fig)
 
 
 
 
 
 
 
493
  else:
494
- st.write("No words available to create a word cloud.")
495
-
496
 
497
 
498
  new_line()
 
418
  st.pyplot(fig)
419
  new_line()
420
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
  new_line()
422
  if st.checkbox("Identify Outliers", value=False):
423
  numeric_cols = df.select_dtypes(include=np.number).columns.tolist()
 
466
 
467
  new_line()
468
  if st.checkbox("Show Word Cloud", value=False):
469
+ # Get the list of object-type columns for user to choose from
470
+ text_col_options = df.select_dtypes(include=[np.object, 'string']).columns.tolist()
471
 
472
+ if text_col_options:
473
+ # Let the user select a text column
474
+ text_col = st.selectbox("Select Text Column for Word Cloud", options=text_col_options)
475
+
476
+ # Collect text data, dropping NA values and joining them into a single string
477
+ text_data = ' '.join(df[text_col].dropna()).strip()
478
+
479
+ if text_data: # Check if there is any text data to use
480
+ wordcloud = WordCloud(width=800, height=400).generate(text_data)
481
+ fig, ax = plt.subplots()
482
+ ax.imshow(wordcloud, interpolation='bilinear')
483
+ ax.axis('off')
484
+ st.pyplot(fig)
485
+ else:
486
+ st.error("No words available to create a word cloud. Please check the selected text data.")
487
  else:
488
+ st.error("No suitable text columns found for creating a word cloud.")
 
489
 
490
 
491
  new_line()