Skip to content
Laviyx Learn

Try

Final-year project

Crop Recommendation System with Machine Learning

A machine learning app that suggests suitable crops from soil nutrients (N, P, K), pH, temperature, humidity and rainfall, compares several models, and explains its suggestion.

Intermediate 6–8 weeks 2–3 studentsUpdated

Pythonpandasscikit-learnMatplotlib or seabornStreamlit or Flask

The problem

Choosing the right crop for a field depends on soil nutrients and climate. A soil test gives values for nitrogen (N), phosphorus (P), potassium (K) and pH. This project trains a model that suggests suitable crops from these values plus weather, and presents the result in a simple app a farmer or agriculture student could use.

A commonly used public dataset is the Crop Recommendation dataset on Kaggle, with about 2,200 rows covering 22 crops. Treat it as a learning dataset: before relying on any suggestion, compare it with local agricultural advice.

Features to build

  • Exploratory analysis: distributions of each feature by crop, and correlations
  • Train and compare at least four models: KNN, decision tree, random forest and one more, such as logistic regression or gradient boosting
  • Use cross-validation and a held-out test set, and report accuracy, precision, recall and a confusion matrix
  • Show the top 3 suggested crops with their predicted probabilities, not just one answer
  • Explain the result with feature importance from the random forest
  • A form-based app where users enter soil-test values and get suggestions
  • Input checks that warn when values are outside the range seen in training

Build plan

  1. 1

    Explore the data

    Load the CSV with pandas, check for missing values and duplicates, check that classes are balanced, and plot each feature by crop.

  2. 2

    Prepare features

    Split into train and test sets with stratification. Put scaling and the model in a pipeline, since KNN and logistic regression need scaled features but tree models do not.

  3. 3

    Train and compare

    Use 5-fold cross-validation on the training data to compare models, then tune the best one's main settings.

  4. 4

    Test honestly

    Evaluate the final model once on the test set and look at which crops get confused with each other.

  5. 5

    Explain and build the app

    Show feature importances, save the pipeline with joblib, and build a Streamlit or Flask app with input validation.

  6. 6

    Write up the limits

    Explain that the dataset is small and clean, so a very high test score does not mean the model will work as well on real fields.

Learn these first

Each part of the project is taught in one of these free lessons.

Make it stand out

  • Fill temperature, humidity and rainfall automatically from a weather API for the user's district
  • Collect a small set of real soil-test reports from your area and test the model on them
  • Add fertiliser suggestions for missing nutrients
  • Support Telugu and Hindi in the app

Viva and interview questions

Try to answer each one aloud before you open it.

  • Why does KNN need feature scaling but a random forest does not?

    KNN measures distances, so a feature with large numbers, like rainfall in millimetres, would dominate small ones like pH. Trees split on one feature at a time using thresholds, so the scale of a feature does not change the splits.

  • Your model gets about 99% accuracy. Is it ready for farmers?

    No. The dataset is small, clean and evenly balanced, and real soil tests, weather and farming conditions are messier. The model must be tested on real local data and checked with agricultural experts before anyone relies on it.

  • What does feature importance tell you?

    How much each feature helped the random forest reduce errors across its splits. It shows which inputs drive the predictions, but not whether a feature causes good yields.

  • Why show the top 3 crops instead of one?

    Several crops can suit the same conditions, and farmers also consider price, water and market access. Showing the top choices with probabilities is more useful and more honest about uncertainty.

What to put in your project report

  1. Abstract: the problem, your solution and the result in one paragraph.
  2. Introduction and problem statement: who has the problem and why it matters.
  3. Requirements: the features (functional) and qualities such as speed and security (non-functional).
  4. Design: architecture diagram, database tables or data flow, and screen layouts.
  5. Implementation: the main modules and the most interesting code, explained.
  6. Testing: the test cases you ran, with inputs, expected and actual results.
  7. Results: screenshots or numbers that show the project working.
  8. Conclusion and future scope: what you achieved and what you would add next.

Your college may give its own format. Follow that first, and use this list to check nothing is missing.

All project ideas →