-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomparison.py
66 lines (55 loc) · 2.37 KB
/
comparison.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import streamlit as st
import pandas as pd
import matplotlib.pyplot as plt
# Load the dataset
df = pd.read_csv("Crop_recommendation.csv")
def show_comparison():
st.title("Crop Comparison")
st.subheader("Select Crops to Compare")
crops = df['label'].unique()
crop1 = st.selectbox("Select Crop 1", crops)
crop2 = st.selectbox("Select Crop 2", crops)
if crop1 == crop2:
st.warning("Please select two different crops for comparison.")
return
st.subheader(f"Comparison of {crop1} and {crop2}")
comparison_df = df[df['label'].isin([crop1, crop2])]
# Display descriptive statistics for the selected crops
st.write("### Descriptive Statistics")
st.write(comparison_df.groupby('label').describe())
# Example of additional information and comparisons
st.write("### Detailed Comparison")
# Example values for conditions; replace with actual data if available
conditions = {
crop1: {
'Optimal Temperature (°C)': 25, # Replace with actual value
'Optimal Rainfall (mm)': 800, # Replace with actual value
'Optimal Soil pH': 6.5 # Replace with actual value
},
crop2: {
'Optimal Temperature (°C)': 20, # Replace with actual value
'Optimal Rainfall (mm)': 600, # Replace with actual value
'Optimal Soil pH': 7.0 # Replace with actual value
}
}
st.markdown(f"""
- **{crop1}:**
- Optimal Temperature: {conditions[crop1]['Optimal Temperature (°C)']} °C
- Optimal Rainfall: {conditions[crop1]['Optimal Rainfall (mm)']} mm
- Optimal Soil pH: {conditions[crop1]['Optimal Soil pH']}
- **{crop2}:**
- Optimal Temperature: {conditions[crop2]['Optimal Temperature (°C)']} °C
- Optimal Rainfall: {conditions[crop2]['Optimal Rainfall (mm)']} mm
- Optimal Soil pH: {conditions[crop2]['Optimal Soil pH']}
""")
# Plotting if needed
st.write("### Feature Comparison")
fig, ax = plt.subplots()
for crop in [crop1, crop2]:
subset = df[df['label'] == crop]
ax.hist(subset['temperature'], alpha=0.5, label=crop)
ax.set_xlabel('Temperature (°C)')
ax.set_ylabel('Frequency')
ax.set_title('Temperature Distribution')
ax.legend(loc='best')
st.pyplot(fig)