Machine Learning in Precision Agriculture: From Pest Detection to Crop Optimization