# Building a machine learning model to predict crop yields based on environmental data

I have a dataset containing data on temperature, precipitation and soybean yields for a farm for 10 years (2005 - 2014). I would like to predict yields for 2015 based on this data.

Please note that the dataset has DAILY values for temperature and precipitation, but only 1 value per year for the yield, since harvesting of crop happens at end of growing season of crop.

I want to build a regression or some other machine learning based model to predict 2015 yields, based on a regression/some other model derived by studying the relation between yields and temperature and precipitation in previous years.

I am familiar with performing machine learning using scikit-learn. However, not sure how to represent this problem. The tricky part here is that temperature and precipitation are daily but yield is just 1 value per year.

How do I approach this?

• even i'm trying to build a model to predict crop yield. Could you please share the details about the approach you are following?
– Nitz
Feb 8 '17 at 11:34
• Were you able to get a complete answer. If no, please let me know and I will be happy to write a detailed answer on how to go about it given I work in the same domain Jun 8 '18 at 14:07
• @Crop89, that would be great! looking forward to your answer Jun 8 '18 at 23:22
• Have you figured it out? I'm facing the same problem. Could you share the details if you have worked it out? much thanks Oct 12 '18 at 2:00

For starters, you can predict the yield for the upcoming year based on the daily data for the previous year. You can estimate the model parameters by considering each year's worth of data as one "point", then validate the model using cross-validation. You can extend this model by considering more than the past year, but look back too far and you'll have trouble validating your model and overfit.

• thanks @Emre, my confusion is that how do I treat an entire year's worth of data as 1 point? Doesn't each row of data (representing one day) constitute a sample in scikit-learn nomenclature? How do I treat an entire year as one sample rather than 365? Jan 4 '16 at 0:26
• I was not addressing the specifics of sklearn, but since you asked, you want to be using the sklearn.cross_validation methods with "Label" in the name, such as sklearn.cross_validation.LabelKFold.
– Emre
Jan 4 '16 at 0:33
• thanks @Emre, so the idea is to assign each year a single label, right? Jan 4 '16 at 1:05
• Yes, @user308827.
– Emre
Jan 4 '16 at 1:51
• thanks again @Emre, please have a look at the follow-up question: datascience.stackexchange.com/questions/9612/… Jan 4 '16 at 15:18

You have 10 data points with each data point having 365 (temperature for each day) + 365 (precipitation for each day) dimensions. Ideally, I would first reduce dimensions via machine learning methods, e.g. PCA. Then use machine learning methods to build a prediction model. However, due to the small dataset, I don't think machine learning techniques are appropriate to your problem.

You can use a Bayesian Belief Network for prediction. Here is a link for basic explanation: Bayesian Network