varshitha22 commited on
Commit
05522ef
·
verified ·
1 Parent(s): 7820224

Update pages/EDA.py

Browse files
Files changed (1) hide show
  1. pages/EDA.py +17 -17
pages/EDA.py CHANGED
@@ -5,7 +5,7 @@ import seaborn as sns
5
  import matplotlib.pyplot as plt
6
 
7
  st.markdown(
8
- "<h3 style='text-align: left; color: #555; font-size: 23px;'>Data Frame</h3>",
9
  unsafe_allow_html=True
10
  )
11
 
@@ -20,10 +20,10 @@ df = pd.read_csv("https://huggingface.co/spaces/varshitha22/Crop_Recommendation/
20
  num_cols = ['Nitrogen', 'Phosphorus', 'Potassium', 'Temperature', 'Humidity', 'pH_Value', 'Rainfall']
21
 
22
  # Title
23
- st.markdown("<h2 style='text-align: left; color: #2E86C1;font-size: 23px;'>Outlier Detection and Handling</h2>", unsafe_allow_html=True)
24
 
25
  # --- Boxplot Visualization ---
26
- st.markdown("<h3 style='text-align: left; color: #D35400;font-size: 23px;'>Outlier Detection (Boxplots)</h3>", unsafe_allow_html=True)
27
 
28
  fig, ax = plt.subplots(2, 4, figsize=(12, 6))
29
  ax = ax.flatten()
@@ -36,7 +36,7 @@ plt.tight_layout()
36
  st.pyplot(fig)
37
 
38
  # --- Outlier Handling ---
39
- st.markdown("<h3 style='text-align: left; color: #28B463;font-size: 23px;'>Outlier Handling using IQR</h3>", unsafe_allow_html=True)
40
 
41
  outlier_counts = {}
42
 
@@ -59,7 +59,7 @@ st.write("Number of Outliers Detected:")
59
  st.write(outlier_counts)
60
 
61
  # Title with color
62
- st.markdown("<h2 style='text-align: left; color: #2E86C1;font-size: 23px;'>Why Use the IQR Method?</h2>", unsafe_allow_html=True)
63
 
64
  # Explanation with smaller font size
65
  st.markdown("""
@@ -81,7 +81,7 @@ st.markdown("""
81
  </div>
82
  """, unsafe_allow_html=True)
83
 
84
- st.markdown("<h2 style='text-align: left; color: #D35400;font-size: 23px;'>Crop Recommendation System - Feature Visualization</h2>", unsafe_allow_html=True)
85
  # List of available visualizations
86
  visualizations = [
87
  "Nitrogen Requirement per Crop",
@@ -151,7 +151,7 @@ ax.set_title("Proportion of Crops", fontsize=3)
151
  st.pyplot(fig)
152
 
153
  # Above-Average Nutrient Requirement Crops
154
- st.markdown("<h2 style='text-align: left; color: #D35400;font-size: 23px;'>Crops that require above-average soil nutrients</h2>", unsafe_allow_html=True)
155
 
156
  # Calculate average nutrient levels
157
  avg_nitrogen = df['Nitrogen'].mean()
@@ -180,7 +180,7 @@ more_avg_of_soil_nutrients = df[
180
  plot_nutrient_crops(more_avg_of_soil_nutrients, "Crops Growing in Nutrient-Rich Soil")
181
 
182
  # Insights for Nutrient-Rich Crops
183
- st.markdown("<h2 style='color: #2E86C1; font-size: 23px;'>Insights:</h2>", unsafe_allow_html=True)
184
  st.markdown("""
185
  <style>
186
  .insights-box {
@@ -200,7 +200,7 @@ st.markdown("""
200
  """, unsafe_allow_html=True)
201
 
202
  # Below-Average Nutrient Requirement Crops
203
- st.markdown("<h2 style='text-align: left; color: #D35400;font-size: 23px;'>Crops that require below-average soil nutrients</h2>", unsafe_allow_html=True)
204
 
205
  # Plot: Crops in Nutrient-Poor Soil
206
  less_avg_of_soil_nutrients = df[
@@ -212,7 +212,7 @@ less_avg_of_soil_nutrients = df[
212
  plot_nutrient_crops(less_avg_of_soil_nutrients, "Crops Growing in Nutrient-Poor Soil")
213
 
214
  # Insights for Nutrient-Poor Crops
215
- st.markdown("<h2 style='color: #D35400; font-size: 23px;'>Insights:</h2>", unsafe_allow_html=True)
216
  st.markdown("""
217
  <style>
218
  .insights-box {
@@ -230,8 +230,8 @@ st.markdown("""
230
  3. Unlike Banana and Rice, which need nutrient-rich soil to grow well, crops like Orange, Mango, and Coconut can survive with fewer nutrients. These fruit trees are naturally more resistant to dry conditions and can grow even in sandy or less fertile soils.<br>
231
  </div>
232
  """, unsafe_allow_html=True)
233
- st.markdown("<h2 style='color: #2E86C1; font-size: 23px;'>How This Helps Farmers:</h2>", unsafe_allow_html=True)
234
- st.markdown("<h2 style='color: #28B463; font-size: 20px;'>Choosing the Right Crops for Low-Fertility Soil:</h2>", unsafe_allow_html=True)
235
  st.markdown("""
236
  <style>
237
  .insights-box {
@@ -248,7 +248,7 @@ st.markdown("""
248
  2. Instead, they can plant fruit trees like Orange, Mango, and Coconut, which can survive and produce good yields even in poor soil.<br>
249
  </div>
250
  """, unsafe_allow_html=True)
251
- st.markdown("<h2 style='color: #28B463; font-size: 20px;'>Improving Soil Naturally with Legumes:</h2>", unsafe_allow_html=True)
252
  st.markdown("""
253
  <style>
254
  .insights-box {
@@ -273,7 +273,7 @@ st.markdown("""
273
 
274
 
275
 
276
- st.markdown("<h2 style='text-align: left; color: #D35400;font-size: 23px;'>Crops that require above-average climate factors</h2>", unsafe_allow_html=True)
277
 
278
  # Calculate average of climate factors
279
  avg_Temperature = df['Temperature'].mean()
@@ -473,7 +473,7 @@ fig, ax = plt.subplots(figsize=(6, 4)) # Reduced size
473
  sns.scatterplot(data=df, x="Rainfall", y="Crop", hue="Crop", palette="rainbow", legend=False, ax=ax)
474
  ax.set_xlabel("Rainfall (mm)", fontsize=8)
475
  ax.set_ylabel("Crop", fontsize=8)
476
- ax.set_title("Rainfall vs Crop Type", fontsize=5)
477
  st.pyplot(fig)
478
 
479
  st.markdown("<h2 style='color: #D35400; font-size: 23px;'> Temperature vs. Humidity</h2>", unsafe_allow_html=True)
@@ -481,14 +481,14 @@ fig, ax = plt.subplots(figsize=(6, 4)) # Reduced size
481
  sns.scatterplot(data=df, x="Temperature", y="Humidity", alpha=0.6, color="blue", ax=ax)
482
  ax.set_xlabel("Temperature (°C)", fontsize=8)
483
  ax.set_ylabel("Humidity (%)", fontsize=8)
484
- ax.set_title("Temperature vs Humidity", fontsize=5)
485
  st.pyplot(fig)
486
 
487
  st.markdown("<h2 style='color: #2E86C1; font-size: 23px;'> Correlation Heatmap of Soil & Climate Factors</h2>", unsafe_allow_html=True)
488
  corr_matrix = df[['Nitrogen', 'Phosphorus', 'Potassium', 'Temperature', 'Humidity', 'pH_Value', 'Rainfall']].corr()
489
  fig, ax = plt.subplots(figsize=(6, 4)) # Reduced size
490
  sns.heatmap(corr_matrix, annot=True, cmap="coolwarm", ax=ax)
491
- ax.set_title("Correlation Heatmap", fontsize=5)
492
  st.pyplot(fig)
493
 
494
  st.markdown("<h2 style='color: #D35400; font-size: 23px;'> 🌾 Crop Recommendations by Season</h2>", unsafe_allow_html=True)
 
5
  import matplotlib.pyplot as plt
6
 
7
  st.markdown(
8
+ "<h3 style='text-align: left; color: #555; font-size: 24px;'>Data Frame</h3>",
9
  unsafe_allow_html=True
10
  )
11
 
 
20
  num_cols = ['Nitrogen', 'Phosphorus', 'Potassium', 'Temperature', 'Humidity', 'pH_Value', 'Rainfall']
21
 
22
  # Title
23
+ st.markdown("<h2 style='text-align: left; color: #2E86C1;font-size: 24px;'>Outlier Detection and Handling</h2>", unsafe_allow_html=True)
24
 
25
  # --- Boxplot Visualization ---
26
+ st.markdown("<h3 style='text-align: left; color: #D35400;font-size: 24px;'>Outlier Detection (Boxplots)</h3>", unsafe_allow_html=True)
27
 
28
  fig, ax = plt.subplots(2, 4, figsize=(12, 6))
29
  ax = ax.flatten()
 
36
  st.pyplot(fig)
37
 
38
  # --- Outlier Handling ---
39
+ st.markdown("<h3 style='text-align: left; color: #28B463;font-size: 24px;'>Outlier Handling using IQR</h3>", unsafe_allow_html=True)
40
 
41
  outlier_counts = {}
42
 
 
59
  st.write(outlier_counts)
60
 
61
  # Title with color
62
+ st.markdown("<h2 style='text-align: left; color: #2E86C1;font-size: 24px;'>Why Use the IQR Method?</h2>", unsafe_allow_html=True)
63
 
64
  # Explanation with smaller font size
65
  st.markdown("""
 
81
  </div>
82
  """, unsafe_allow_html=True)
83
 
84
+ st.markdown("<h2 style='text-align: left; color: #D35400;font-size: 24px;'>Crop Recommendation System - Feature Visualization</h2>", unsafe_allow_html=True)
85
  # List of available visualizations
86
  visualizations = [
87
  "Nitrogen Requirement per Crop",
 
151
  st.pyplot(fig)
152
 
153
  # Above-Average Nutrient Requirement Crops
154
+ st.markdown("<h2 style='text-align: left; color: #D35400;font-size: 24px;'>Crops that require above-average soil nutrients</h2>", unsafe_allow_html=True)
155
 
156
  # Calculate average nutrient levels
157
  avg_nitrogen = df['Nitrogen'].mean()
 
180
  plot_nutrient_crops(more_avg_of_soil_nutrients, "Crops Growing in Nutrient-Rich Soil")
181
 
182
  # Insights for Nutrient-Rich Crops
183
+ st.markdown("<h2 style='color: #2E86C1; font-size: 24px;'>Insights:</h2>", unsafe_allow_html=True)
184
  st.markdown("""
185
  <style>
186
  .insights-box {
 
200
  """, unsafe_allow_html=True)
201
 
202
  # Below-Average Nutrient Requirement Crops
203
+ st.markdown("<h2 style='text-align: left; color: #D35400;font-size: 24px;'>Crops that require below-average soil nutrients</h2>", unsafe_allow_html=True)
204
 
205
  # Plot: Crops in Nutrient-Poor Soil
206
  less_avg_of_soil_nutrients = df[
 
212
  plot_nutrient_crops(less_avg_of_soil_nutrients, "Crops Growing in Nutrient-Poor Soil")
213
 
214
  # Insights for Nutrient-Poor Crops
215
+ st.markdown("<h2 style='color: #D35400; font-size: 24px;'>Insights:</h2>", unsafe_allow_html=True)
216
  st.markdown("""
217
  <style>
218
  .insights-box {
 
230
  3. Unlike Banana and Rice, which need nutrient-rich soil to grow well, crops like Orange, Mango, and Coconut can survive with fewer nutrients. These fruit trees are naturally more resistant to dry conditions and can grow even in sandy or less fertile soils.<br>
231
  </div>
232
  """, unsafe_allow_html=True)
233
+ st.markdown("<h2 style='color: #2E86C1; font-size: 24px;'>How This Helps Farmers:</h2>", unsafe_allow_html=True)
234
+ st.markdown("<h2 style='color: #28B463; font-size: 22px;'>Choosing the Right Crops for Low-Fertility Soil:</h2>", unsafe_allow_html=True)
235
  st.markdown("""
236
  <style>
237
  .insights-box {
 
248
  2. Instead, they can plant fruit trees like Orange, Mango, and Coconut, which can survive and produce good yields even in poor soil.<br>
249
  </div>
250
  """, unsafe_allow_html=True)
251
+ st.markdown("<h2 style='color: #28B463; font-size: 24px;'>Improving Soil Naturally with Legumes:</h2>", unsafe_allow_html=True)
252
  st.markdown("""
253
  <style>
254
  .insights-box {
 
273
 
274
 
275
 
276
+ st.markdown("<h2 style='text-align: left; color: #D35400;font-size: 24px;'>Crops that require above-average climate factors</h2>", unsafe_allow_html=True)
277
 
278
  # Calculate average of climate factors
279
  avg_Temperature = df['Temperature'].mean()
 
473
  sns.scatterplot(data=df, x="Rainfall", y="Crop", hue="Crop", palette="rainbow", legend=False, ax=ax)
474
  ax.set_xlabel("Rainfall (mm)", fontsize=8)
475
  ax.set_ylabel("Crop", fontsize=8)
476
+ ax.set_title("Rainfall vs Crop Type", fontsize=3)
477
  st.pyplot(fig)
478
 
479
  st.markdown("<h2 style='color: #D35400; font-size: 23px;'> Temperature vs. Humidity</h2>", unsafe_allow_html=True)
 
481
  sns.scatterplot(data=df, x="Temperature", y="Humidity", alpha=0.6, color="blue", ax=ax)
482
  ax.set_xlabel("Temperature (°C)", fontsize=8)
483
  ax.set_ylabel("Humidity (%)", fontsize=8)
484
+ ax.set_title("Temperature vs Humidity", fontsize=3)
485
  st.pyplot(fig)
486
 
487
  st.markdown("<h2 style='color: #2E86C1; font-size: 23px;'> Correlation Heatmap of Soil & Climate Factors</h2>", unsafe_allow_html=True)
488
  corr_matrix = df[['Nitrogen', 'Phosphorus', 'Potassium', 'Temperature', 'Humidity', 'pH_Value', 'Rainfall']].corr()
489
  fig, ax = plt.subplots(figsize=(6, 4)) # Reduced size
490
  sns.heatmap(corr_matrix, annot=True, cmap="coolwarm", ax=ax)
491
+ ax.set_title("Correlation Heatmap", fontsize=3)
492
  st.pyplot(fig)
493
 
494
  st.markdown("<h2 style='color: #D35400; font-size: 23px;'> 🌾 Crop Recommendations by Season</h2>", unsafe_allow_html=True)