Technological advancements have revolutionized livestock farming, notably in health monitoring. Traditional methods, which have been criticized for subjectivity and treatment delays, can be replaced with efficient health monitoring systems, thereby reducing costs and workload. Implementing cow behavior recognition allows for effective dairy cow health monitoring. In this research, we propose an integrated system using inertial measurement unit (IMU) devices and machine learning techniques for dairy cow behavior recognition. Six main dairy cow behaviors were studied: lying, standing, walking, drinking, feeding, and ruminating. All behavior types were manually labeled into the IMU data by reviewing the recorded footage. The labeled IMU data underwent four processing steps: selecting different window sizes, feature extraction, feature selection, and normalization. These processed data were then used to build the behavior recognition model. Various model structures, including SVM, Random Forest, and XGBoost, were tested. The top-performing model, XGBoost, with its proposed 58 features achieved an F1-score of 0.87, with specific scores of 0.93 for lying, 0.85 for walking, 0.94 for ruminating, 0.89 for feeding, 0.86 for standing, 0.93 for drinking, and 0.59 for other activities. During our online testing, we observed similar patterns for each healthy cow. The cumulative time spent on each behavior also matched the statistics from previous surveys. Additionally, our backend optimization approach resulted in a final overall percentage error of 1.55 % per day during online testing. In conclusion, our study presents an IMU-based system capable of accurately recognizing dairy cow behavior. Feature design and appropriate models are proposed herein. A functional optimization method was introduced indicating that our system has the potential with applications for estrus detection and other reproductive management practices in the dairy industry.