kusht55 commited on
Commit
9f7f461
·
verified ·
1 Parent(s): 2c69c26

Delete crop_selector2.py

Browse files
Files changed (1) hide show
  1. crop_selector2.py +0 -43
crop_selector2.py DELETED
@@ -1,43 +0,0 @@
1
- import pandas as pd
2
- import streamlit as st
3
- from sklearn.naive_bayes import GaussianNB
4
-
5
- dataset = pd.read_csv(r"C:\Users\Kush\Desktop\hackathons\IITB\Crop_selection.csv")
6
- features = dataset[['N', 'P', 'K', 'temperature', 'humidity', 'ph', 'rainfall']]
7
- target = dataset['label']
8
-
9
- prices = pd.read_csv(r"C:\Users\Kush\Desktop\hackathons\IITB\crop_prices.csv")
10
-
11
-
12
- model = GaussianNB()
13
- model.fit(features, target)
14
-
15
- st.title("Crop Selection App")
16
-
17
- st.header("Input Soil Data:")
18
- nitrogen = st.number_input("Nitrogen", min_value=0, max_value=100, value=50)
19
- phosphorus = st.number_input("Phosphorus", min_value=0, max_value=100, value=50)
20
- potassium = st.number_input("Potassium", min_value=0, max_value=100, value=50)
21
- temperature = st.number_input("Temperature", min_value=0.0, max_value=100.0, value=25.0,step=1.,format="%.4f")
22
- humidity = st.number_input("Humidity", min_value=0.0, max_value=100.0, value=50.0,step=1.,format="%.4f")
23
- ph = st.number_input("pH", min_value=0.0, max_value=14.0, value=7.0,step=1.,format="%.4f")
24
- rainfall = st.number_input("Rainfall", min_value=0.0, max_value=1000.0, value=500.0,step=1.,format="%.4f")
25
-
26
- user_input = [[nitrogen, phosphorus, potassium, temperature, humidity, ph, rainfall]]
27
-
28
- if st.button("Predict"):
29
- predicted_crop = model.predict_proba(user_input)
30
-
31
- crop_probabilities = list(zip(model.classes_, predicted_crop[0]))
32
-
33
- # Sort crops based on probability estimates
34
- sorted_crops = sorted(crop_probabilities, key=lambda x: x[1], reverse=True)
35
-
36
- # Display the sorted crops
37
- st.header("Top 3 Crops to grow:")
38
- for i, (crop, probability) in enumerate(sorted_crops[:3]):
39
- prob_percent = probability*100
40
- #st.write(f"{i+1}. {crop}: {prob_percent:.2f}%")
41
- average_price = prices.loc[prices['CROP'] == crop, 'AVG PRICES'].values[0]
42
-
43
- st.write(f"{i+1}. {crop}: {prob_percent:.2f}% || Average Price: Rs.{average_price} / Quintal")