Artificial Intelligence in Agriculture: Crop Recommendation System.

Shoyombo Raphael
4 min read6 days ago

--

Imagine a farmer trying to decide what to plant. Traditionally, it’s a bit of a guessing game. They might choose a crop and then try to make the land work for it, adding fertilizers or manure. But this can be expensive, and sometimes, it even causes problems. Too much manure, for example, can throw off the soil’s balance, introduce harmful germs, or even make the soil too salty.

But what if there was a smarter way?

That’s where “Precision Agriculture” comes in. Think of it as high-tech farming. Instead of guessing, farmers use data and technology to make better decisions. They gather information about everything from the soil to the weather to figure out the best way to grow crops.

This article is about how we can use some really cool technology — called machine learning and artificial intelligence — to help farmers even more. We’ve built a system that acts like a personal crop advisor. It takes information about the soil (like the levels of important nutrients like Nitrogen, Potassium, and Phosphorus) and the environment (temperature, pH, humidity, and rainfall) and then recommends the best crops to plant.

Think of it like this: Imagine you’re going to cook a meal. You wouldn’t just throw ingredients together without a recipe, right? Our system is like a recipe for successful farming. It tells farmers exactly what “ingredients” (crops) will work best given the conditions of their “kitchen” (land).

How does it work? We feed all that soil and weather data into a computer program. This program has “learned” which crops thrive in different conditions. So, when a farmer provides information about their land, the program can make smart recommendations.

This approach has huge benefits:

More Food, Less Waste: By planting the right crops in the right places, farmers can grow more food, reducing waste and increasing their income.
Saving Money: Farmers can avoid spending money on unnecessary fertilizers or other treatments.
Protecting the Environment: By using less fertilizer, we can reduce pollution and protect our environment.

We believe that this technology can revolutionize farming, making it more efficient, profitable, and sustainable. If you’re interested in learning more about the data we used to build this system, you can find it here. We’re excited about the future of smart farming!

Dataset for crop recommendation.

A dataset with information on 22 different crops was used to train the system. This dataset can be thought of as a “library” of knowledge about these crops. It includes 100 examples for each crop, showing how they grow under different conditions. By studying these examples, the system learns the patterns and relationships between the soil, weather, and crop growth. Now, when a farmer provides information about their land, the system can use this learned knowledge to give personalized recommendations.

Value counts for each crop in the dataset

To get the system ready, the crop data was carefully organized and prepared. This involved cleaning the data and making sure it was in a format the system could easily understand. With this well-organized information, the system was then trained to recognize the patterns between soil, weather, and successful crop growth.

Rounded up the floats and set them to 2 decimal places
Outcome of rounding up.

The numbers were rounded up to make things a bit simpler, and because most common thermometers, for example, don’t give outputs in 6 decimal places.

Label Mapping

To make things clear, each crop in the dataset was given a unique number. This way, when the system suggests a crop, it uses these numbers, making it easy for anyone to see which crop is being recommended. So, if the system outputs the number 1, it might mean maize(as seen in the above screenshot), and so on.

Data splitting

To build and test the system, the data was split into two sets. One set was used to train the system, teaching it the relationships between soil, weather, and crop growth. The other set was used to check how well the system learned and how accurately it could make recommendations.

Random Forest Classifier

The system learned using a technique called Random Forest, which is like having many different experts giving their opinions. This approach made the system very accurate, with a success rate of over 99%.

saved the model

Beyond accuracy, the model’s performance was evaluated using metrics like precision, recall, and F1-score. The trained model was then saved for integration into user-friendly software, enabling easy access to its crop recommendation capabilities.

All codes and updates on this project can be found here.

--

--

Shoyombo Raphael
Shoyombo Raphael

Written by Shoyombo Raphael

I’m a machine learning engineer, cybersecurity enthusiast, automotive enthusiast and lifelong learner.

No responses yet