🏆
Global Knowledge Platform
Serving Researchers Since 2012

A Lightweight ML-Based Web System for Real-Time Crop and Fertilizer Recommendation

DOI : https://doi.org/10.5281/zenodo.20362610
Download Full-Text PDF Cite this Publication

Text Only Version

A Lightweight ML-Based Web System for Real-Time Crop and Fertilizer Recommendation

Divya Gupta

Department of Computer Science and Engineering Vignans Foundation for Science, Technology

and Research, Guntur, Andhra Pradesh, India, 522213

Anushka Singh

Department of Computer Science and Engineering Vignans Foundation for Science, Technology

and Research, Guntur, Andhra Pradesh, India, 522213

Chinna Gopi Simhadri*

Department of Computer Science and Engineering Vignans Foundation for Science, Technology

and Research Guntur, Andhra Pradesh, India, 522213

Abstract – Agricultural productivity is signicantly inuenced by soil nutrients and environmental conditions, yet traditional crop selection methods often rely on limited knowledge, leading to inefcient resource utilization and reduced yield. This paper proposes a lightweight machine learning-based web system for real-time crop and fertilizer recommendation. The system ana-lyzes key parameters such as nitrogen, phosphorus, potassium, temperature, humidity, rainfall, and soil pH to predict suitable crops and recommend appropriate fertilizers. Multiple machine learning models, including Decision Tree, Random Forest, SVM, KNN, and Logistic Regression, are evaluated. Experimental results show that the Random Forest model achieves the highest accuracy of 99.31%, while the Decision Tree model is selected for deployment due to its lower computational complexity and faster execution. The system is implemented as a web application using the Flask framework, enabling farmers to obtain real-time recommendations easily.

Index TermsArticial Intelligence, Crop Prediction, Decision Tree, Fertilizer Recommendation, Machine Learning, Precision Agriculture, Smart Farming, Soil Nutrient Analysis.

  1. Introduction

    Agriculture is really important for making sure we have food to eat. It also helps the economy in countries, like India that are still growing. Agriculture does a lot of things for these places. Crop yield is largely dependent on the nutrient status of the soil, climatic factors, and fertilizer management practices. However, farmers generally adopt conventional farming prac-tices and human decision-making while choosing the crops to be cultivated, which might lead to low crop yield and economic losses for the farmers. Therefore, intelligent decision-making tools are of vital importance in the enhancement of agricultural productivity.

    Articial Intelligence and Machine Learning are getting better and better.This means we can make agricultural prac-tices better by looking at all the information we get from the soil and the environment.Articial Intelligence and Machine Learning can help us decide which crops to grow.We can use Machine Learning to gure out which crops will do well in our area.It checks things like how many nutrientsre in the soil how

    much rain we get, how humid it is and how hot or cold it is.It also checks how acidic or basic the soil is.All this information helps us choose the crops.The Machine Learning algorithms look at the soil and the weather to tell us which crops will grow well.We can use this information to grow crops that do well in our soil and weather.The soil needs to have the amount of nutrients for the crops to grow.The amount of rainfall and humidity and temperature all play a part in deciding which crops we can grow.The pH of the soil is also very important, for the crops.[1].

    Many crop recommendation systems only think about what crop to plant and do not think about what fertilizer to use. This is a problem because fertilizer is just as important as the crop for keeping the soil healthy and making sure we get a lot of food from the farm. This system uses ML to nd out what crop to plant and what fertilizer to use. It looks at the soil and the environment to make these decisions. The crop prediction and fertilizer recommendation system uses all of these things to decide what to do. The system is used for determining crops and suggesting fertilizers based on the condition of the soil and the environment.

    this approach, supervised machine learning methods are applied to data set preprocessing, training prediction models, and evaluating the performance of prediction models. To make this accessible to farmers, the system is built into a simple web app using the Flask framework, so recommendations can be delivered quickly and easily.

    The main points of this study are summarized below:

    * We want to make a model that can predict which crops will grow well. This model will use information about the soil and the environment.

    * We also want to help farmers use fertilizers efciently. This means creating a system that recommends the amount and type of fertilizer based on the soils nutrients.

    * Lastly we plan to build a web application that farmers can use in real-time to get advice, on crop and fertilizer management.

    The proposed work differs signicantly from existing sys-tems, as this work includes both crop prediction and fertilizer recommendations using a ML approach. This system provides real-time recommendations using a light-weight web appli-cation, thereby enhancing efcient decision-making by the farmer community.

    The structure of this paper is described as follows: Section II: This section talks about studies that are related to crop prediction using machine learning-based techniques. Section III: This section concludes proposed methodology and system architecture for developing the crop prediction system using soil and environmental parameters. Section IV: This section concludes experimental results and performance evaluation of the proposed predictive models. Section V: This section concludes the overall work done in this research and provides possible future work.

  2. Literature Review

    Some people who study crops have tried to use machine learning to gure out how crops will do. They want to know how much crops will produce. Ramesh and his team came up with a way to predict crops using a method called forest. This method is good because it can handle the farm data. They are trying to predict crops with this method.The random forest algorithm is good for predicting crops because farm data is not always easy to understand.Patel and Shah proposed a model that can predict crops using SVM. They got results but it was hard to choose the right parameters.Kumar and his team proposed a way to predict crops using deep learning techniques. They got results but it took a lot of computer power to do it. Ramesh and his team used the forest method, for crop prediction. Crop prediction is what they are trying to do. They used the forest algorithm for crop prediction.

    People who work with precision agriculture systems try to guess how crops will do.Kalmani and others made a system that suggests what crops to plant using XGBoost and Random Forest methods.This system is really good at making guesses. It gets it right 99.3 percent of the time.Sawan and others also made a system that tries to guess how crops will do.They used Random Forest, SVM and LSTM methods.This system is also very good.It has a score of 0.963.This score shows how well it makes guesses.Anwar proposed a way to predict crops based on weather conditions.He used Random Forest and SVR methods.The R2 value was 0.875.There is no feature related to soil in his method.Crop prediction and soil conditions are very important.Random Forest and crop prediction are used together.The crop prediction system uses Random Forest.The system is good, at making crop predictions.

    With the advent of advanced deep lerning architectures, researchers have also used sequential models for time series

    to achieve R2 = 0.84 by integrating remote sensing and crop growth data. In addition to this, Yan et al. [9] have also used a combination of Transformer and GRU techniques using reinforcement learning to achieve MAE = 0.85 and also improved irrigation efciency by 35

    Ensemble and Sensor-based Methods have also received considerable attention in recent days. Priyanka et al. [10] im-plemented a random forest, XGBoost, ANN, and LSTM-based system for the prediction of soil moisture, which proved to be highly reliable with a high R2 0.90 for IoT-based datasets. Similarly, Jabed et al. [11] implemented a random forest and GBM-based system for the prediction of maize yield, which proved to be highly reliable with a high R2 = 0.89.

    With the integration of remote sensing technologies, re-searchers have improved spatial prediction accuracy. Vi-jayabaskaran and Singla [12] used Random Forest, Gradient Boosting, and Decision Trees, achieving R2 > 0.75. Mishra et al. [13] proposed early prediction models using Random Forest and regression techniques, achieving less than 26% error and enabling timely agricultural decision-making. Furthermore, Muruganantham et al. [14] introduced Vision Transformer-based approaches such as Prithvi-EO, achieving an RMSE of

    0.44 and R2 was 0.81, demonstrating strong performance in

    satellite-based yield prediction.

    Recent advancements have also explored object detec-tion and computer vision techniques in agriculture. Kolipaka and Namburu [15] proposed a YOLO-based framework that achieved mAP@0.5 was 93.3% for plant health detection, highlighting the potential of real-time monitoring systems, although it does not directly address yield prediction.

    Even though we are making progress in predicting crops using ML and DL most research has focused on how ac-curate the predictions are, not on helping farmers make de-cisions.The proposed approach looks at the decision-making process.It combines the Decision Tree method with a web platform. These techniques are being used to make predictions more accurate.However the proposed approach goes further by integrating with a web platform.This integration makes the prediction process more efcient.Farmers can quickly get predictions. Make informed decisions.The Decision Tree approach is used to make predictions.It is a yet effective method.The web platform makes it easy to deploy and use.This system helps farmers make the decisions.It uses ML and DL to improve predictions.The proposed approach is a step in the direction.It addresses the limitations of research.The focus is, on a suggesting system.This system is fast, interpretable and deployable.

    TABLE I: Comparative Literature Survey

    agricultural data. Singh et al. [7] have also developed a

    framework using DNN, ANN, and LSTM techniques to reduce

    Author Year Method Strength Limitation

    the Mean Absolute Error by 40%. In addition, the determining

    Ramesh et al.

    2020 Random Forest High accuracy No deployment

    Patel & Shah

    2021 SVM

    Good classication Complex tuning

    capability of the model was also improved under climate

    Kumar et al.

    2022 Deep Learning Strong performance High computation

    variability conditions. Similarly, Elbasi et al. [8] have also used a combination of LSTM and Random Forest techniques

    Proposed Work 2026 Decision Tree + Web Fast and deployable Dataset dependent

  3. Materials and methods

    The system they are talking about is going to use the data to gure out what crops can be grown grounded on the nutrients in the soil and the weather. This system is supposed to help people make decisions when it comes to farming.

    The system is shown in the picture : Fig. 1

    The system has a lot of things to consider. The soil in the system has things like nitrogen and phosphorus and potassium. It also looks at the temperature. The system is really, about the soil and the weather and the crops that can be grown in it. Preprocessing of the dataset is performed to handle missing values and normalize features using StandardScaler or Min-MaxScaler. Machine learning models are trained to determine patterns for crop suitability, and Decision Tree classier pro-vided a good trade-off between precision and efciency. The trained model is used to develop a website based on Flask to

    give farmers real-time crop and fertilizer suggestions.

    1. Inputs

      • Nitrogen

      • Phosphorus

      • Potassium

      • Temperature

    2. Description of Collected Data

      The data used for this study is grounded on a publicly available data set used for crop recommendations. The data set has approximately 2,200 records, and the features include data such as N, P, K, T, H, R, and pH. This data set has all kinds of environmental factors and crops, and it can be used for any kind of machine learning-based predictions. At this level, the data concerning agriculture is collected with the help of historical data concerning soil and climate. The attributes that are used at this level are N, P, K, T, H, R, and pH.

      Each agricultural sample is represented as a feature vector dened as:

      x = [N, P, K, T, H, R, pH] (1)

      The feature vector dened in (1) denotes the entire prole of environmental and soil conditions used for crop prediction.

    3. Data Preprocessing

      The agricultural data collected undergoes preprocessing to remove inconsistencies and improve model performance.

      1. Feature Scaling: Since the attributes have different units and ranges, StandardScaler normalization is applied.

        x

        • Humidity

        • pH

          xscaled =

          (2)

        • Rainfall

        The method we are talking about is grounded on using intelligence and ML to Suggest crops and suggest the right fer-tilizers. This is done by looking at things that have to do with

      2. Label Encoding: The crop data is converted into numer-ical data in order to be compatible with the machine learning model.

        the soil and the environment. We use intelligence and machine learning to make these predictions and suggestions, about crops and fertilizers. The proposed architecture is divided into

        y = LabelEncoder(crop)

        where y represents the encoded crop class.

        (3)

        three different levels or sections, namely Data sourcing and aggregation , data preprocessing and feature engineering, and the modeling and prediction engine.

        1) Fertilizer Recommendation Logic: The fertilizer recom-mendation is based on what the soils missing, like nitrogen, phosphorus and potassium. We look at what nutrientsre not enough in the soil. Then we use the predicted crop and nutrient levels to gure out what fertilizer to use. This is done by following some rules to recommend the right fertilizers, for the soil and the crop like nitrogen and phosphorus and potassium fertilizers. For example, deciency of nitrogen can be addressed by using urea, whereas phosphorus and potassium deciencies can be addressed by using DAP and MOP fertilizers.

        TABLE II: Datasets Used for Crop Prediction

      3. TrainTest Splitting: The information we have is split

      into two parts: the train data and the test data.

      D = Dtrain Dtest (4)

      Typically, 80% is used for training and 20% for testing to ensure unbiased evaluation.

    4. Modeling and Prediction

    Multiple supervised machine learning algorithms are evalu-ated for crop prediction.

    1. Random Forest Model: Random Forest maks decision trees and then combines what they predict. We use this to make a guess, about what fertilizers to use, like nitrogen, phosphorus and potassium to help the crop grow.

      T

      Dataset Name

      Description

      No. of Records

      Croprecommendation.csv

      Raw soilclimate dataset

      2,200+

      Preprocessed data.csv

      Cleaned data for ML training

      2,000+

      Newunseendata.csv

      Samples for testing

      200+

      y = 1 f (x) (5)

      T t

      t=1

      where T is the number of trees and ft(x) represents the prediction of the tth tree.

      Fig. 1: Architecture of ML-Based Web System for Real-Time Crop and Fertilizer Recommendation

    2. Logistic Regression: Logistic regression is a method that uses the sigmoid function to guess the chance of something belonging to a class.

      1

      P (y = 1|x) = (6)

      1+ e(wT x+b)

      where w is the weight vector and b is the bias.

    3. Model Evaluation Metrics: We look at how our models are doing by using some standard ways to measure how good they are, at putting things into categories and this helps us evaluate the performance of the fertilizer recommendation models specically the models that recommend fertilizers.

    Accuracy:

    TP + TN

    The proposed AI-based pipeline is a viable solution for precision agriculture, as it enables the farmer to make choices about crop selection and fertilizers.

  4. Experimental Results and Discussion

    The crop recommendation system was built using the Python programming language and Visual Studio Code De-velopment Environment. The crop recommendation system was the central issue of analysis. This system uses machine learning algorithms to provide crop recommendations for the farmers. The crop recommendation system prepares the data, normalize the features, trains and deployed on the web for

    Accuracy =

    Precision:

    TP + TN + FP + FN

    TP

    (7)

    easier access. Various machine learning models were used in the development of this system. These models included Decision Tree, Random Forest, SVM, K-nearest neighbors and Logistic Regression. The above algorithms were used

    Recall:

    Precision =

    TP + FP

    (8)

    to analyze data based on soil and environmental conditions like Nitrogen, Phosphorous, Potassium, temperature, humidity, rainfall and pH value. The above algorithm was used to

    analyze data based on soil and environmental conditions to

    F1 Score:

    TP

    Recall =

    TP + FN

    Precision × Recall F 1 = 2 ×

    Precision + Recall

    (9)

    (10)

    improve the crop recommendation system. The above factors affect the performance of the application. Therefore, this system uses these factors to make crop recommendations for farmers. Performance of the crop recommendation system was assessed through the analysis of the data generated by the experiment. It can be noted that the crop recommendation

    where TP denotes True Positives, TN denotes True Neg-atives, FP denotes False Positives, and FN denotes False Negatives.

    The Random Forest model had the highest accuracy of 99.31%, but the Decision Tree classier was selected for the nal implementation due to its lower computational complex-ity and faster execution time.

    system is a great benet to the farmers as it helps them in decision-making. Results From the experiment carried out in developing the precision crop recommendation system, it became evident that the random forest classier performed better than other classiers since it had accuracy of 99.31%.We compared the results we got from the machine learning model. Presented them in Table IV.

    Fig. 2: Comparative Study of Algorithm Accuracy

    1. Model Accuracy Comparison

      Fig. 2 below shows the result obtained after performing the evaluation of different machine learning algorithms used for predicting crop production. Some of the best machine learning algorithms that can be used to predict crops include the random forest algorithm, decision tree algorithm, SVM, KNN, and logistic regression, among others.

    2. Evaluation Using Confusion Matrix

      Fig. 3: Classication Analysis of Random Forest Crop Predic-tion Model

      However, when considering the confusion matrix that was developed through the use of the random forest classier shown in Figure 3, the crops which have been predicted by the developed model can be established. The observations from the confusion matrix above show that the predictions have been placed along the diagonal line. This is an indication that there

      have been few mistakes made while predicting the types of crops through the random forest classier model.

    3. Model Evaluation Results

      TABLE III: Analysis of Predictive Accuracy

      Model

      Accuracy

      Random Forest

      0.993182

      Decision Tree

      0.986364

      SVM

      0.968182

      KNN

      0.965909

      Logistic Regression

      0.963636

      TABLE IV: Cross Validation Accuracy

      Model

      Mean CV Accuracy

      Random Forest

      0.9949

      Decision Tree

      0.9864

      SVM

      0.9847

      KNN

      0.9773

      Logistic Regression

      0.9699

      As presented in table IV, the output of the Random Forest evaluation model shows an accuracy of 0.9931 in classifying the data. It is indeed worthy to be noted that the accuracy of the Random Forest model, according to the cross-validation test performed, showed an accuracy of 0.9949.

    4. Feature Importance Analysis

      Fig. 4: Evaluation of Feature Relevance in Random Forest Model

      This insight guides the selection and optimization of key variables to improve model accuracy and agricultural decision-making. As shown in Fig. 4, rainfall and humidity have signif-icant inuence on crop prediction, followed by soil nutrients such as potassium , phosphorus , and nitrogen . Temperature and pH also contribute to the prediction process.

    5. System Interface

      The trained model was used by deploying a machine learn-ing model using a web application, making it easier for farmers to use. This is illustrated in Fig. 5, where one can input values

      Fig. 5: Crop and Fertilizer Advisor Web Interface

      for soil nutrient content, e.g., N, P, K, and pH, as well as environmental factors. Weather information may be obtained automatically based on the location of the user.

    6. Prediction Output

    Fig. 6: Example crop recommendation output generated by the system

    The last prediction output of the system is shown in Fig. 6. According to the input parameters provided to the system, the proposed model has predicted Muskmelon as the most suitable crop for planting and Urea fertilizer for use. The results we got from our experiment show that our intelligent crop recommendation system is really good at predicting what crops will do well. This system is very helpful for farmers who work in the eld of agriculture and have to make decisions, about their crops. Our intelligent crop recommendation system gives farmers the information they need to make choices.

    It is evident from the result that the suggested approach of Random Forest is more accurate than the suggested Decision Tree approach due to the complicated nature of he suggested

    approach, but the suggested Decision Tree approach is fast in providing result in real time for farmers. The suggested ap-proach is dependent on environmental conditions, like rainfall and humidity.

  5. Conclusion and Future Work

The work proposes a way to suggest crops and fertiliz-ers.The system is designed to use machine learning for farmers make data-driven decisions.It looks at soil nutrient levels to recommend crops.The system also suggests fertilizers to improve soil nutrients.The goal is to make it easy for farmers to access and use.The system was built using machine learning steps.It has a web interface for easy access.The results show that this system is effective.It has accuracy and low computa-tional complexity.This makes it suitable, for real-time use.The system can help farmers choose the crops and fertilizers.It considers soil nutrient values to make suggestions.The system aims to improve farming practices.

References

  1. W. Wang, Q. Zhang, and F. Yu, Progress in Research on Deep Learning-Based Crop Yield Prediction, Agronomy, vol. 14, no. 10, 2024.

  2. K. Meghraoui, I. Sebari, and J. Pilz, Applied Deep Learning-Based Crop Yield Prediction: Current Developments and Challenges, Tech-nologies, vol. 12, no. 4, 2024.

  3. D. S. Dhaliwal and M. M. Williams, Sweet Corn Yield Prediction Using Machine Learning Models, Precision Agriculture, 2024.

  4. V. H. Kalmani, N. V. Dharwadkar, and V. Thapa, Crop Yield Predic-tion using CNN-LSTM Deep Learning Algorithm, Indian Journal of Agricultural Research, 2025.

  5. V. Sawan, R. Kumari, and M. Kayal, Machine Learning Based Method for Forecasting Crop Yield, Journal of Recent Innovations in Computer Science and Technology, vol. 2, no. 3, 2025.

  6. M. H. Anwar, Crop Yield Prediction Using Machine Learning, Journal of Innovative Computing and Emerging Technologies, vol. 4, no. 2, 2024.

  7. A. Singh et al., Crop Yield Prediction using Machine Learning and Deep Learning Techniques, Procedia Computer Science, vol. 218, pp. 406417, 2023.

  8. E. Elbasi et al., Crop Prediction Model Using Machine Learning Algorithms, Applied Sciences, vol. 13, no. 16, 2023.

  9. A. Venugopal et al., Crop Yield Prediction using Machine Learning Algorithms, IJERT, 2021.

  10. P. Priyanka et al., Crop Yield Prediction using Machine Learning,

    IJARCCE, 2025.

  11. M. A. Jabed et al., Crop Yield Prediction in Agriculture: A Compre-hensive Review, Heliyon, 2024.

  12. V. Vijayabaskaran and G. Singla, Machine Learning Based Crop Yield Prediction: A Review, Journal of Agricultural Science and Technology, 2025.

  13. S. Mishra et al., Crop Yield Prediction using Machine Learning: A Systematic Review, Agricultural Technology, 2024.

  14. S. Mishra et al., Machine Learning for Precision Agriculture and Crop Yield Prediction, International Journal of Intelligent Systems, 2024.

  15. J. Muruganantham et al., Crop Yield Prediction with Deep Learning and Remote Sensing, Remote Sensing, vol. 14, no. 9, 2022.

  16. Y. Yan, Y. Wang, and J. Li, Crop Yield Prediction Based on Hybrid Machine Learning Models, arXiv preprint, 2025.

  17. R. Kumar et al., Hybrid Machine Learning Model for Crop Yield Prediction, Research in Intelligent Automation, 2023.

  18. A. Patel et al., Crop Yield Prediction Using Machine Learning,

    International Journal of Innovative Science, 2024.

  19. R. Kolipaka and A. Namburu, Machine Learning and Deep Learning Techniques for Crop Prediction, IJCCTS, vol. 14, no. 1, 2023.

  20. S. Ramesh, P. Reddy, and K. Rao, Prediction and Analysis of Crop Yield using Machine Learning Techniques, IJERT, vol. 10, no. 05, 2021.