saherPervaiz commited on
Commit
1f9976d
·
verified ·
1 Parent(s): 98a7876

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -26
app.py CHANGED
@@ -3,60 +3,73 @@ import pandas as pd
3
  from utils.data_cleaning import handle_missing_values, remove_outliers_iqr, cap_extreme_values
4
  from utils.visualizations import plot_correlation_heatmap, save_plot_as_png
5
  from utils.model_training import train_all_models
 
6
 
7
- # File uploader
8
  st.title("Model Training with Metrics and Correlation Heatmap")
9
 
10
  # File uploader with unique keys
11
- uploaded_file_1 = st.file_uploader("Choose a CSV file for data", type=["csv"], key="file_uploader_1")
12
- uploaded_file_2 = st.file_uploader("Choose another CSV file for reference", type=["csv"], key="file_uploader_2")
13
 
14
- if uploaded_file_1 is not None:
15
- st.write("File 1 uploaded successfully!")
16
-
17
- if uploaded_file_2 is not None:
18
- st.write("File 2 uploaded successfully!")
19
- # Show the dataset
20
- st.write("Dataset:")
21
  st.dataframe(df)
22
 
23
- # Clean data: Missing values, outliers, and extreme values
24
- df = handle_missing_values(df)
25
- df = remove_outliers_iqr(df)
26
- df = cap_extreme_values(df)
 
27
 
28
  st.write("Cleaned Dataset:")
29
- st.dataframe(df)
30
 
31
- # Add clean data download option
32
  st.subheader("Download Cleaned Dataset")
33
  st.download_button(
34
  label="Download Cleaned Dataset (CSV)",
35
- data=df.to_csv(index=False),
36
  file_name="cleaned_dataset.csv",
37
  mime="text/csv"
38
  )
39
 
40
  # Correlation Heatmap
41
  st.subheader("Correlation Heatmap")
42
- corr_plot = plot_correlation_heatmap(df)
43
  st.pyplot(corr_plot)
44
 
45
  # Save heatmap as PNG
46
- heatmap_buf = save_plot_as_png(corr_plot)
 
 
 
 
47
  st.download_button(
48
  label="Download Correlation Heatmap as PNG",
49
- data=heatmap_buf,
50
  file_name="correlation_heatmap.png",
51
  mime="image/png"
52
  )
53
 
54
- # Target and features selection
55
- target = st.selectbox("Select Target Variable", df.columns)
56
- features = [col for col in df.columns if col != target]
57
- X = df[features]
58
- y = df[target]
 
59
 
60
- # Train and evaluate models
 
61
  model_results = train_all_models(X, y) # Train all models based on data type
 
62
  st.dataframe(model_results)
 
 
 
 
 
 
 
 
 
3
  from utils.data_cleaning import handle_missing_values, remove_outliers_iqr, cap_extreme_values
4
  from utils.visualizations import plot_correlation_heatmap, save_plot_as_png
5
  from utils.model_training import train_all_models
6
+ import io
7
 
8
+ # Streamlit App Title
9
  st.title("Model Training with Metrics and Correlation Heatmap")
10
 
11
  # File uploader with unique keys
12
+ uploaded_file = st.file_uploader("Upload a CSV file for data analysis", type=["csv"], key="file_uploader_1")
 
13
 
14
+ if uploaded_file is not None:
15
+ # Read the uploaded file into a DataFrame
16
+ df = pd.read_csv(uploaded_file)
17
+ st.write("Dataset Uploaded Successfully!")
 
 
 
18
  st.dataframe(df)
19
 
20
+ # Clean Data: Missing values, outliers, and extreme values
21
+ st.subheader("Data Cleaning")
22
+ df_cleaned = handle_missing_values(df)
23
+ df_cleaned = remove_outliers_iqr(df_cleaned)
24
+ df_cleaned = cap_extreme_values(df_cleaned)
25
 
26
  st.write("Cleaned Dataset:")
27
+ st.dataframe(df_cleaned)
28
 
29
+ # Add download option for the cleaned dataset
30
  st.subheader("Download Cleaned Dataset")
31
  st.download_button(
32
  label="Download Cleaned Dataset (CSV)",
33
+ data=df_cleaned.to_csv(index=False),
34
  file_name="cleaned_dataset.csv",
35
  mime="text/csv"
36
  )
37
 
38
  # Correlation Heatmap
39
  st.subheader("Correlation Heatmap")
40
+ corr_plot = plot_correlation_heatmap(df_cleaned)
41
  st.pyplot(corr_plot)
42
 
43
  # Save heatmap as PNG
44
+ heatmap_buffer = io.BytesIO()
45
+ corr_plot.savefig(heatmap_buffer, format='png')
46
+ heatmap_buffer.seek(0)
47
+
48
+ # Download Button for Heatmap
49
  st.download_button(
50
  label="Download Correlation Heatmap as PNG",
51
+ data=heatmap_buffer,
52
  file_name="correlation_heatmap.png",
53
  mime="image/png"
54
  )
55
 
56
+ # Target and Feature Selection
57
+ st.subheader("Select Target and Features")
58
+ target = st.selectbox("Select Target Variable", df_cleaned.columns)
59
+ features = [col for col in df_cleaned.columns if col != target]
60
+ X = df_cleaned[features]
61
+ y = df_cleaned[target]
62
 
63
+ # Train and Evaluate Models
64
+ st.subheader("Model Training and Evaluation")
65
  model_results = train_all_models(X, y) # Train all models based on data type
66
+ st.write("Model Training Results:")
67
  st.dataframe(model_results)
68
+
69
+ # Add download option for model results
70
+ st.download_button(
71
+ label="Download Model Results (CSV)",
72
+ data=model_results.to_csv(),
73
+ file_name="model_results.csv",
74
+ mime="text/csv"
75
+ )