Spaces:
Sleeping
Sleeping
Update pages/EDA.py
Browse files- pages/EDA.py +27 -27
pages/EDA.py
CHANGED
|
@@ -86,25 +86,28 @@ st.markdown("""
|
|
| 86 |
# Streamlit App
|
| 87 |
st.title("Crop Recommendation System - Feature Visualization")
|
| 88 |
|
| 89 |
-
#
|
| 90 |
-
|
| 91 |
-
"
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
| 101 |
)
|
| 102 |
|
| 103 |
# Function to plot feature distributions per crop
|
| 104 |
def plot_feature(feature, title):
|
| 105 |
avg_feature_per_crop = df.groupby("Crop")[feature].mean().reset_index()
|
| 106 |
|
| 107 |
-
fig, axes = plt.subplots(1, 2, figsize=(
|
| 108 |
|
| 109 |
# Bar plot
|
| 110 |
sns.barplot(data=avg_feature_per_crop, x=feature, y="Crop", palette="rainbow", ax=axes[0])
|
|
@@ -121,18 +124,15 @@ def plot_feature(feature, title):
|
|
| 121 |
st.pyplot(fig)
|
| 122 |
|
| 123 |
# Display selected plot
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
plot_feature("pH_Value", "pH Value")
|
| 136 |
-
elif viz_option == "Rainfall Distribution per Crop":
|
| 137 |
-
plot_feature("Rainfall", "Rainfall")
|
| 138 |
|
|
|
|
| 86 |
# Streamlit App
|
| 87 |
st.title("Crop Recommendation System - Feature Visualization")
|
| 88 |
|
| 89 |
+
# List of available visualizations
|
| 90 |
+
visualizations = [
|
| 91 |
+
"Nitrogen Requirement per Crop",
|
| 92 |
+
"Phosphorus Requirement per Crop",
|
| 93 |
+
"Potassium Requirement per Crop",
|
| 94 |
+
"Temperature Distribution per Crop",
|
| 95 |
+
"Humidity Distribution per Crop",
|
| 96 |
+
"pH Value Distribution per Crop",
|
| 97 |
+
"Rainfall Distribution per Crop"
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
# Slider for visualization selection
|
| 101 |
+
viz_option = st.select_slider(
|
| 102 |
+
"Select a visualization:",
|
| 103 |
+
options=visualizations
|
| 104 |
)
|
| 105 |
|
| 106 |
# Function to plot feature distributions per crop
|
| 107 |
def plot_feature(feature, title):
|
| 108 |
avg_feature_per_crop = df.groupby("Crop")[feature].mean().reset_index()
|
| 109 |
|
| 110 |
+
fig, axes = plt.subplots(1, 2, figsize=(10, 4)) # Decreased plot size
|
| 111 |
|
| 112 |
# Bar plot
|
| 113 |
sns.barplot(data=avg_feature_per_crop, x=feature, y="Crop", palette="rainbow", ax=axes[0])
|
|
|
|
| 124 |
st.pyplot(fig)
|
| 125 |
|
| 126 |
# Display selected plot
|
| 127 |
+
feature_mapping = {
|
| 128 |
+
"Nitrogen Requirement per Crop": "Nitrogen",
|
| 129 |
+
"Phosphorus Requirement per Crop": "Phosphorus",
|
| 130 |
+
"Potassium Requirement per Crop": "Potassium",
|
| 131 |
+
"Temperature Distribution per Crop": "Temperature",
|
| 132 |
+
"Humidity Distribution per Crop": "Humidity",
|
| 133 |
+
"pH Value Distribution per Crop": "pH_Value",
|
| 134 |
+
"Rainfall Distribution per Crop": "Rainfall",
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
plot_feature(feature_mapping[viz_option], viz_option)
|
|
|
|
|
|
|
|
|
|
| 138 |
|