Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -30,7 +30,7 @@ def plot_correlation_matrix(data):
|
|
30 |
|
31 |
# Function to calculate feature importance
|
32 |
def calculate_feature_importance(X, y):
|
33 |
-
#
|
34 |
le = LabelEncoder()
|
35 |
y_encoded = le.fit_transform(y) # Transform y into continuous integers
|
36 |
|
@@ -65,6 +65,35 @@ def calculate_feature_importance(X, y):
|
|
65 |
|
66 |
return importance_dict
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
# Streamlit app
|
69 |
st.title('Heart Disease Feature Analysis')
|
70 |
|
|
|
30 |
|
31 |
# Function to calculate feature importance
|
32 |
def calculate_feature_importance(X, y):
|
33 |
+
# Encode non-sequential class labels to sequential integers
|
34 |
le = LabelEncoder()
|
35 |
y_encoded = le.fit_transform(y) # Transform y into continuous integers
|
36 |
|
|
|
65 |
|
66 |
return importance_dict
|
67 |
|
68 |
+
# Example of usage in the main script
|
69 |
+
# After uploading the file and selecting the target column, run the analysis
|
70 |
+
if uploaded_file is not None:
|
71 |
+
data = pd.read_csv(uploaded_file)
|
72 |
+
st.write("Data Preview:")
|
73 |
+
st.write(data.head())
|
74 |
+
|
75 |
+
# Select target variable
|
76 |
+
target_col = st.selectbox("Select the target variable", data.columns)
|
77 |
+
|
78 |
+
if st.button('Analyze'):
|
79 |
+
X = data.drop(target_col, axis=1)
|
80 |
+
y = data[target_col]
|
81 |
+
|
82 |
+
# Ensure that `y` has continuous integer values for classification
|
83 |
+
st.write("Original Target Values:", y.unique()) # Show original target values for debugging
|
84 |
+
|
85 |
+
# Correlation Matrix
|
86 |
+
st.subheader('Correlation Matrix')
|
87 |
+
plot_correlation_matrix(data)
|
88 |
+
|
89 |
+
# Feature Importance
|
90 |
+
st.subheader('Feature Importance')
|
91 |
+
importance_dict = calculate_feature_importance(X, y)
|
92 |
+
|
93 |
+
# Create a DataFrame with all feature importances
|
94 |
+
importance_df = pd.DataFrame(importance_dict, index=X.columns)
|
95 |
+
st.write(importance_df)
|
96 |
+
|
97 |
# Streamlit app
|
98 |
st.title('Heart Disease Feature Analysis')
|
99 |
|