Inspiration
Farmers often have access to soil test values such as pH, nitrogen, phosphorus, potassium, organic matter, and electrical conductivity, but these numbers can be difficult to interpret without technical knowledge. I wanted to build a simple tool that could turn soil data into understandable insights and practical soil-management guidance. This led me to create AI Soil Health Advisor, a decision-support tool that combines machine-learning insights with transparent, rule-based soil assessment.
What It Does
AI Soil Health Advisor allows users to enter key soil parameters including soil pH, organic matter, nitrogen (N), phosphorus (P), potassium (K), electrical conductivity (EC), soil texture, and target crop. The application provides two complementary types of output: • ML-Based Fertility Insight: A machine-learning model predicts soil fertility based on patterns learned from a labeled soil dataset. • Rule-Based Soil Health Assessment: Evaluates soil properties using agronomic thresholds and provides an overall soil health score, crop and texture guidance, and actionable recommendations. The two components are intentionally kept separate. The ML model provides a data-driven fertility insight, while the rule-based layer provides transparent and interpretable soil-management guidance.
How I Built It
• Interface: Developed using Python and Streamlit to create an interactive and accessible web application. • Dataset & Preparation: Used a labeled dataset containing 880 soil samples with N, P, K, pH, EC, and organic carbon (OC) features. The dataset was examined for missing values, duplicate records, feature distributions, and class imbalance. • Model Selection: Compared multiple approaches and evaluated them using stratified cross-validation. The final model was a Balanced Random Forest, selected for its stronger balance between overall performance and minority-class detection. • Model Performance: The final approach achieved approximately 89% cross-validation accuracy with a 0.78 macro F1-score. • Agronomic Rule Engine: Implemented explicit soil-property thresholds to convert user inputs into a composite soil health score, crop and texture analysis, and practical management recommendations.
Challenges I ran into
• Class Imbalance: The highly fertile class represented only a small portion of the dataset, so accuracy alone was not sufficient for evaluating model performance. I therefore considered macro F1-score and class-specific performance during model evaluation. • Hybrid System Design: Maintaining a clear distinction between machine-learning predictions and rule-based agronomic recommendations was important to avoid presenting the two systems as if they measured exactly the same thing. • Feature Mapping: The training dataset uses organic carbon (OC), while the application collects organic matter (OM) from users. This required careful consideration when connecting the user-facing inputs to the ML model.
Accomplishments I’m Proud of
• Built a complete working AI-powered soil health prototype from dataset analysis to model integration and web deployment. • Successfully implemented both machine-learning fertility prediction and transparent rule-based soil assessment in one application. • Evaluated the ML approach using stratified cross-validation rather than relying only on a single train-test split. • Achieved approximately 89% cross-validation accuracy with a 0.78 macro F1-score while considering the underrepresented highly fertile class. • Developed an interactive interface that converts multiple soil parameters into understandable soil-health insights and practical recommendations.
What I Learned
This project gave me hands-on experience with an end-to-end machine-learning application workflow, from dataset inspection and model evaluation to model integration and Streamlit deployment. I also learned that building a useful AI application is not only about achieving a strong performance metric. Interpretability, responsible use of predictions, clear communication, and domain knowledge are equally important when applying machine learning to agriculture.
What's Next for AI Soil Health Advisor
• Future versions could include larger and more geographically diverse soil datasets, additional soil properties, and locally calibrated fertility thresholds. • Future versions could include confidence estimates for ML predictions and integration with location-specific agronomic recommendations. • The current application is intended as a preliminary decision-support tool, not a replacement for laboratory soil testing or professional agronomic advice.
Built With
- imbalanced-learn
- joblib
- machine-learning
- pandas
- python
- scikit-learn
- streamlit
Log in or sign up for Devpost to join the conversation.