Mattral commited on
Commit
30a2c91
·
verified ·
1 Parent(s): 4eb234c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +94 -0
app.py CHANGED
@@ -393,6 +393,100 @@ df.drop(columns={col_to_delete}, inplace=True)
393
  col1, col2, col3 = st.columns([1, 0.7, 1])
394
  if col2.button("Show DataFrame", use_container_width=True):
395
  st.dataframe(df, use_container_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
 
397
 
398
  # Missing Values
 
393
  col1, col2, col3 = st.columns([1, 0.7, 1])
394
  if col2.button("Show DataFrame", use_container_width=True):
395
  st.dataframe(df, use_container_width=True)
396
+
397
+ #start point
398
+
399
+ # Histograms for Numerical Features
400
+ hist = st.checkbox("Show Histograms", value=False)
401
+ new_line()
402
+ if hist:
403
+ numeric_cols = df.select_dtypes(include=np.number).columns.tolist()
404
+ col_for_hist = st.selectbox("Select Column for Histogram", options=numeric_cols)
405
+ num_bins = st.slider("Select Number of Bins", min_value=10, max_value=100, value=30)
406
+ fig, ax = plt.subplots()
407
+ df[col_for_hist].hist(bins=num_bins, ax=ax, color='skyblue')
408
+ ax.set_title(f'Histogram of {col_for_hist}')
409
+ st.pyplot(fig)
410
+ new_line()
411
+
412
+ # Box Plots for Numerical Features
413
+ boxplot = st.checkbox("Show Box Plots", value=False)
414
+ new_line()
415
+ if boxplot:
416
+ numeric_cols = df.select_dtypes(include=np.number).columns.tolist()
417
+ col_for_box = st.selectbox("Select Column for Box Plot", options=numeric_cols)
418
+ fig, ax = plt.subplots()
419
+ df.boxplot(column=[col_for_box], ax=ax)
420
+ ax.set_title(f'Box Plot of {col_for_box}')
421
+ st.pyplot(fig)
422
+ new_line()
423
+
424
+ # Scatter Plots for Numerical Features
425
+ scatter = st.checkbox("Show Scatter Plots", value=False)
426
+ new_line()
427
+ if scatter:
428
+ numeric_cols = df.select_dtypes(include=np.number).columns.tolist()
429
+ x_col = st.selectbox("Select X-axis Column", options=numeric_cols, index=0)
430
+ y_col = st.selectbox("Select Y-axis Column", options=numeric_cols, index=1 if len(numeric_cols) > 1 else 0)
431
+ fig, ax = plt.subplots()
432
+ df.plot(kind='scatter', x=x_col, y=y_col, ax=ax, color='red')
433
+ ax.set_title(f'Scatter Plot between {x_col} and {y_col}')
434
+ st.pyplot(fig)
435
+ new_line()
436
+
437
+ # Pair Plots for Numerical Features
438
+ pairplot = st.checkbox("Show Pair Plots", value=False)
439
+ new_line()
440
+ if pairplot:
441
+ sns.pairplot(df.select_dtypes(include=np.number))
442
+ st.pyplot()
443
+
444
+ # Count Plots for Categorical Data
445
+ countplot = st.checkbox("Show Count Plots", value=False)
446
+ new_line()
447
+ if countplot:
448
+ categorical_cols = df.select_dtypes(include=['object', 'category']).columns.tolist()
449
+ col_for_count = st.selectbox("Select Column for Count Plot", options=categorical_cols)
450
+ fig, ax = plt.subplots()
451
+ sns.countplot(x=df[col_for_count], data=df, ax=ax)
452
+ ax.set_title(f'Count Plot of {col_for_count}')
453
+ st.pyplot(fig)
454
+ new_line()
455
+
456
+ # Pie Charts for Categorical Data
457
+ pie_chart = st.checkbox("Show Pie Charts", value=False)
458
+ new_line()
459
+ if pie_chart:
460
+ categorical_cols = df.select_dtypes(include=['object', 'category']).columns.tolist()
461
+ col_for_pie = st.selectbox("Select Column for Pie Chart", options=categorical_cols)
462
+ pie_data = df[col_for_pie].value_counts()
463
+ fig, ax = plt.subplots()
464
+ ax.pie(pie_data, labels=pie_data.index, autopct='%1.1f%%', startangle=90)
465
+ ax.axis('equal') # Equal aspect ratio ensures that pie is drawn as a circle.
466
+ ax.set_title(f'Pie Chart of {col_for_pie}')
467
+ st.pyplot(fig)
468
+ new_line()
469
+
470
+ # Feature Importance (Only if a model has been trained)
471
+ if 'trained_model' in st.session_state and st.session_state.trained_model is not None:
472
+ feature_importance = st.checkbox("Show Feature Importance", value=False)
473
+ new_line()
474
+ if feature_importance:
475
+ model = st.session_state.trained_model
476
+ importances = pd.Series(model.feature_importances_, index=X_train.columns)
477
+ fig, ax = plt.subplots()
478
+ importances.sort_values().plot(kind='barh', ax=ax)
479
+ ax.set_title('Feature Importance')
480
+ st.pyplot(fig)
481
+ new_line()
482
+
483
+ # Interactive Data Tables
484
+ interactive_table = st.checkbox("Show Interactive Data Table", value=False)
485
+ new_line()
486
+ if interactive_table:
487
+ st.dataframe(df)
488
+ new_line()
489
+
490
 
491
 
492
  # Missing Values