This paper presents a data-driven farming approach based on explainable machine learning (Explainable ML) to address the challenges of cow health monitoring and yield optimization in dairy farms. Continuous data collection using a 3-axis accelerometer sensor and robust ML methodologies and algorithms provide actionable insights into cow activity and behavior, empowering farmers to make informed decisions and adopt sustainable practices. Bluetooth-enabled IoT devices and 4G networks facilitate data transmission, analysis, and inference generation, and model performance is explained through an explainability framework. Focusing on accelerometer time-series data preprocessing (statistical feature extraction, signal processing techniques, and delay-based feature extraction using a sliding window technique), various hyperparameter-optimized ML models are evaluated for activity classification across various window lengths. The k-nearest neighbor classifier achieves the best performance (mean AUC of 0.98 on the training set, standard deviation of 0.0026, and AUC of 0.99 on the test set). Using an explainable AI framework like SHAP, we interpret feature importance in a way that practitioners can understand and use. We develop explainable and practical ML models to support sustainable livestock management through detailed comparison of key features and stability analysis of selected features.