Improving detection of dairy cow estrus using fuzzy logic

Production losses due to lack of precision in detecting estrus in dairy cows are well known and reported in milk production countries. Nowadays automatic estrus detection has become possible as a result of technical progress in continuously monitoring dairy cows using fuzzy pertinence functions. Dairy cow estrus is usually visually detected; however, solely use of visual detection is considered inefficient. Many studies have been carried out to develop an effective model to interpret the occurrence of estrus and detect estrus; however, most models present too many false-positive alerts and because of this they are sometimes considered unreliable. The objective of this research was to construct a system based on fuzzy inference functions evaluated with a receiver-operating characteristic curve, capable of efficiently detect estrus in dairy cows. For the input data the system combined previous estrus cases information and prostaglandin application with the data of cow activities. The system outputs were organized in three categories: ‘in estrus’, ‘maybe in estrus” and ‘not in estrus’. The system validation was carried out in a commercial dairy farm using a herd of 350 lactating cows. The performance of the test was measured by calculating its sensitivity towards the right estrus detection; and its specificity towards the precision of the detection. Within a six months period of tests, over 25 thousands cases of estrus were analyzed from a database of the commercial farm. The sensitivity found was 84.2%, indicating that the system can detect estrus efficiently and it may improve automatic estrus detection.


Introduction
The inefficiency in detecting estrus may lead to an annual loss of 800 million dollars for the milk industry in the USA (Rorie, 2002).In most herds in the USA, the expected estrus detection in large dairy farms is less than 50%, made mainly by visual observation (French and Nebel, 2003).Dairy units in Brazil often use visual detection, and the method is not considered efficient.In order to assist estrus detection, electronic sensor technologies have been developed to measure moving activ-ity (steps per hour), production, basal temperature, and milk electric conductivity of each cow.However, these technologies are not well known by the dairy producers due to their cost and efficiency when applied to specific cases (Firk et al., 2002;Firk et al., 2003).Since usual estrus detection organizes the combination of uncertain information concerning the cow cyclic calendar and the climatic data within a context of uncertainties, fuzzy logic (Zadeh, 1965) may present the necessary adequacy for the construction of an efficient bovine estrus detection computer system (Eradus et al., 1998).
Sci. Agric.(Piracicaba, Braz.), v.67, n.5, p.503-509, September/October 2010 Several authors refer to the improvement of estrus detection in dairy cows (Arney et al., 1994;Eradus et al., 1998).The cow presents distinct signals when in estrus, such as the increase in activity and the acceptance of the mounting of other cows, which is the best visual detection, according to Stevenson et al. (1996).Another important indicator is the increase in activity that can be successfully detected by the use of a pedometer (De Mol and Woldt, 2001).
The objective of this study was to develop and validate a system for automatic estrus detection in Hostein dairy cows using fuzzy inference functions.

Material and Methods
Data were collected in a commercial dairy farm located in São Pedro, State of São Paulo, Brazil (22º32' S, 47º54' W, and altitude of 580 m) maintaining a herd of 750 Holstein -Frisian cows (Bos taurus).The climate in the region is warm and dry with average temperature of 22ºC, and high rain index in the summer and low in winter.To detect cow estrus four input data were used: activity measurements (from pedometers), local ambient temperature, historical estrus calendar from previous estrus occurrences, and prostaglandine induction, which were applied to all cows (Firk et al., 2002).During the trial part of the herd (350 cows) were lactating but only 98 lactating cows had pedometers and had their pregnancy confirmed by progesterone hormone testing.The remaining of the herd was used for visual observation and historical estrus calendar.During the experiment feeding strategy, environment control and management remained the same as in the dairy farm.
Selected information on historical data of cow estrus was used to develop the system inference method.The model was developed based on data-driven information (analyzing the previous estrus cases).A separated set of data was previously collected to determine the proper influence of previous known estrus cases.
The methodology can be explained in three steps: (i) gathering of cow estrus data by organizing the knowledge base and known field data analysis; (ii) development of a fuzzy system, which presented three different proposed alert responses: "in estrus", "not in estrus", and "maybe in estrus", and (iii) system validation.To comply with (i) data were collected for six months in the commercial herd previously described.When a cow was visually detected as in estrus and after insemination became pregnant, it was considered as certain that it was in estrus by the time of insemination.All estrus data which did not result in pregnancy was ignored during the trial.Data collection on the movement of the 98 herd with pedometer between January 15 and August 15, 2007 was organized for later processing (Table 1).The used pedometers (S.A.E Afikim®) had a sensor which was able to record up to 1,000 steps.Movement data were downloaded using an antenna installed in the milking room Cows without pedometer were chosen for extracting knowledge related to the estrus cyclic calendar, while the cows with pedometer were selected for the validation of the developed fuzzy system, as the accuracy of their estrus occurrence was checked by hormonal test.
Data were collected from January through July (total of 335 estrus cases available for the six-month trial).From all these cases only 98 could be used for this study.A large number of estrus cases was discharged: 237 (335 -98) because they either represented cows which did not become pregnant after insemination or were cows without pedometer.The cows that did not become pregnant even with the estrus induction and further insemination were not used for model building, since this condition may have been influenced by other unspecified factors such as environment, management and physiology.
Data from (i) were used for building up a knowledge based fuzzy system (Figure 1) which is implemented in (ii) to predict estrus.Estrus was mostly detected in a natural manner.However, in cases of cows with difficult in have estrus, a prostaglandin hormone was applied, and after the injection, estrus was expected to appear within two to eleven days.Previous knowledge about the occurrence of estrus was obtained in order to design the appropriate pertinence function for each trait: "activity increase", "prostaglandine" and "days since last estrus".
Because the model was also partially data-driven based, a different set of data was collected separately from the group of cows used for the validation of the model.This special data were obtained to study the activity measurements and the estrus cycle.For the activity measurement study 63 cows were randomly selected and analyzed, and for the estrus cycle study a group of 108 cows were also randomly selected and analyzed.The used inference method was Mandani, which com- Sci.Agric.(Piracicaba, Braz.), v.67, n.5, p.503-509, September/October 2010 bines the degree of pertinence referent to each input value using a minimum operator, and aggregates the rules by the maximum operator.The defuzzification was made using the method of gravity, as suggested by Amendola and Souza (2004).
This methodology is in accordance with the studies performed by Firk et al. (2003) and De Mol and Woldt (2001).De Mol and Woldt (2001) improved estrus detection using mathematical tools such as the Kalman Filter and Fuzzy Logic.Firk et al. (2003) presented innovated estrus detection using the estrus cycle data as an input for fuzzy inference functions.For each cow the mean movement rates were calculated for both periods: warm season (January and April, 2007) and cold season (May and August, 2007).The input data including the local environment temperature, activity deviation, prostaglandin hormone induction, and the estrus calendar are part of the structure of the automatic estrus detection fuzzy system.
The methodology used to all the information needed for the pertinence functions included interviews with specialists in estrus detection, as well as available information from previous studies (Firk et al., 2003;De Mol and Woldt, 2001).
The means to detect the estrus was the comparison of the changes which occurred in cow activity values (Firk et al., 2003).A time period of eight days was used to calculate the average movement rate (Equation 1).This calculation compared the average cow movement reading with the last previous milking movement reading (Y 8+1 ).The difference between the milking actual reading and the foreseen reading (Y 8+1 ) was reported as the movement deviation percentage, using a methodology similar to the one adopted by López-Gatius et al. (2003): Eq.1 To reach a higher level of accuracy, a time period was adopted to calculate the movement change based on the last previous eight days, in which the standard error in the data was subtracted, as shown in Equation 2. The average and the standard deviation were calculated based on the movements registered from day 1 to day 7.The option of not including the 8 th day was made because the 9 th day is, in many cases, a day in which there is estrus occurrence, meaning that the movements are not standard (outliers).Therefore, in case a cow presents an estrus in the 9 th day, the 8 th should not be included not to compromise the deviation average of the 9 th day.
System validation was made using all available cows (step 3).Change in movement that exceeded 60% in the average calculated value for the last previous 8 days, was considered as if the cow would have a great chance of being in estrus.Only the data of cows that had pedometer with some movement rate (steps per hour) were selected for validation of the developed fuzzy system.Data from cows without pedometer were selected for the analysis of the days related to the cow fertility cycle calendar.
For the evaluation of the efficiency of the system the negative and positive results were compared to the actual registered estrus data.If the result of the test did not correspond to the actual state of estrus data, then it was assumed that an error has occurred.When the result of the test corresponded to the actual state of estrus, then a correct decision has been made.The responses were given in FP (False Positive), TP (True Positive), FN (False Negative), TN (True Negative); where the first letter indicate that the answer was true or false and the second letter represents the response to the system (Positive or Negative).When the response was positive (in estrus) this result was named TP, only if the actual estrus data was reached, which means the assurance that the cow was surely in estrus.When the response was positive but the actual estrus data was not reached, the result was named FP.In case where the response was negative for those cows not presenting estrus, the result was named TN.The negative results of cows that were surely in estrus were named FN.The testing of the system was made taking into consideration the number of TP, FP, TN, FN responses, according to the criteria of total precision (TP plus TN rate), sensitivity (the TP rate) and 1-specificity, which is the FP rate.
Given a certain number of cows n with results FP, TP, FN and TN, a table of contingence is built.The test performance evaluation used a table of contingence (Table 2) showing the results found by using the fuzzy classifier, when compared to the actual estrus data (Gomes and Monard, 2002).
The precision of the classifying system (as the results presented in the table of contingence) is the broadest computation about the system performance evaluation (Equation 4).It consists in the relation of the number of right cases (right) in relation to the total of cases (n).

Total precision
Eq.4 Gomes and Monard (2002) define precision as a standard measurement to verify hypotheses.It is also used to estimate the confidence of the classifier in correct decision making.The limitation of precision relies on the fact that it does not take into consideration the cases in which the classifier relates as false.In the case of the dairy cows which are about to be "in estrus", it was estimated that only 5% of the cases correspond to cows actually "in estrus", as the cow presents estrus only once every 21 days.Thus, a precision of 0.95 can be reached just making all results to be as "no estrus".However, this could not be taken into account as the trial searched for the estrus estimation.
Both sensitivity (De Mol and Woldt, 2001;Firk et al., 2002) and specificity were estimated (Equations 5 and 6).Sensitivity can be understood as the measure of positive probability for cows detected as in estrus and actually being in estrus.Equation 5 takes into account only the cows which are truly "in estrus", and afterwards both status of alert either "in estrus" (TP) or "no estrus" (FN) may be considered in the fuzzy system.Sensibility compares the cases of positive estrus (TP) with all results attributed to all cows actually "in estrus".Eq.5 The specificity calculates the prevalence of the classifier in nominating cows which are not presenting estrus (Equation 6).

Specificity= right alerts (alerts no estrus) total of alerts for cows trully no estrus = TN (TN+FP)
Eq.6 The calculation of the specificity refers to the probability of the system emitting negative alerts (no estrus) for those cows which are not truly presenting estrus.The sensitivity compares all correct results of "no estrus" (TN) with all given results that did not present estrus and when the inputs indicated that the cows were "in estrus" but they really did not be "in estrus" (FP).The error amount, also called as false positive, corresponds to the incorrect alerts (Equation 7)

Error= wrong alerts in estrus total of cows trully in estrus = F FP (TN+FP)
= -Specificity 1 Eq.7 The confidence of the system as seen by the producer is directly related to the value of the error the automatic estrus detection system generates.This error may be verified using Equations 6 and 7.If the error is large it means that the producer receives indications that the cows are "in estrus" but they are actually not "in estrus".Thus the fuzzy system is efficient when the specificity value is near 100% and the error is near zero.
The point of identification for the division of the cows "in estrus", "maybe in estrus", and "not in estrus" was found from the analysis of Receiver Operating Characteristic (ROC) curve.The ROC curve represents the relation between the true-positive versus the false-positive (sensitivity versus 1 -specificity) from the model classification outputs.The precision represents the relation between true -positive plus true -negative, divided by the total number of observations multiplied by 100.Computational tools were used to process the data and formulate the tables.

Results and Discussion
Data were analyzed in order to study the activity performance and then build up the proper membership function.A maximum deviation of 336% was found (p < 0.001) in relation to days a cow was not presenting estrus.This deviation is widely known to be typical during estrus periods.The outliers of the movement average rate pattern characterize the presence of estrus, and in this experiment they indicate an increment on the movement rate of 184, 288 and 336% (Figure 2).These increments are a high indication of estrus presence.Using the observed movement rate pattern it was possible to define a base of rules that was used for building up the fuzzy pertinence function for predicting the Sci. Agric.(Piracicaba, Braz.), v.67, n.5, p.503-509, September/October 2010 estrus detection, which has the base of rules on activity rate of the cows, resulted in the prediction of estrus fuzzy pertinence function where the increment on activity rate was between 0 to 20%, 21 to 60%, 61 to 130%, and higher than 131% that were classified for prediction of estrus in "very low", "low", "average" and "high", respectively.The historical data on estrus from the other group of cows (G =108) which did not use pedometer, distinct from the other data used for modeling the fuzzy system, was used for building up knowledge related to the interval between estrus.
As the dairy cow ovulates approximately every 21 days it was needed to search for the variation on the difference on the estrus cycle period for each animal.Observational results have shown that approximately 30% of the cows presented estrus within the interval of 18 to 24 days in the first cycle.In the second cycle the estrus was found at 42 days (21 + 21 days); however, the peak occurrence of estrus was distributed along the days within an interval between 38 to 46 days.The base of rules used to built the estrus fuzzy pertinence function using the interval between estrus occurrence were 0 to 17 days, 18 to 24 days, 25 to 36 days and 37 to 47days classified as estrus prediction on classes: "early", "highly expected", "late" and "expected", respectively.
As it is difficult for a cow to ovulate before 18 days after calving the hormone prostaglandin is normally used in order to induce further estrus.This information was organized to build up another set of rules for the prediction of estrus fuzzy pertinence function, regarding the estrus prostaglandin hormonal induction to estrus.The intervals between estrus presence were between 0 to 3, 4 to 11, and higher than 11 for the prostaglandin induction of estrus classified as "not induced", "induced" and "not induced", respectively .The knowledge about estrus cycle calendar and the use of prostaglandin hormone were valuable data for building up the fuzzy pertinence functions using 24 bases of rules.The total of rules used is described in Table 3.
After the input of data in the fuzzy system the output values varied from 0 to 1. Approximately 25,000 possible estrus events were analyzed; these data are from studies of 350 cows and the historical database of the farm.Each of these events corresponds to data of movement rate, estrus calendar, prostaglandin induction which was collected every time the cow entered the milking parlor.A specific response was given for each event.The answer zero indicated the total lack of estrus while the absolute presence of estrus was given the value of 1.The non-parametric method was used for building the ROC curve; and for each chosen point the respective values of 1 relating specificity versus sensitivity were plotted.The curve that was obtained had a line smoothly shaped pattern, instead of the stair pattern shape due to the large number of analyzed events.The area under the ROC curve varies between 1 (when there is a perfect separation between the cow presenting estrus and the cow not presenting estrus), and 0.5 where any conclusion becomes randomized.In this specific study the area below the curve was not calculated, as recommended by De Mol and Woldt ( 2001), and it is highly evident that the area is near to 1 (Figure 2), indicating that the system is sensible to select the presence of estrus in the cows.
The response "may be in estrus" was used to increase the confidence of the system in the alerts "in estrus", in order to increase the chances of correctly indicate a truly positive estrus case.It indicates a "in estrus" alert with a minimum error, while a "may be in estrus" indicates a "in estrus" with a higher admissible error.The ROC curve (Figure 2) shows the interaction between the failure (error -fraction of the false positive) and target of the system (fraction of the positive true).In this experiment the single error in detecting estrus may result in milk production loss for the whole month.Thus, the criterion for determining the positive alerts need to be focused on the attempt to make less mistakes, avoiding false negative results.However, the increase of the alerts TP may not compromise the reliability of the system.In the point where there is an increase in the TP fraction, the set point to differentiate all alerts was chosen.
A region of optimal points corresponding to the tolerance given to the error in this research is shown (Figure 3).The number of alerts (FP) was reduced specially for the value of 0.39 which separates the cows "in estrus" from the ones in "may be in estrus".Based on the ROC curve and the respective interaction of the responses true (TP) and false (FP) that each point may give as response, the following intervals were defined: • Alert " in estrus"= system response between 0.39 and 1; • Alert "may be in estrus" = system response between 0.19 and 0.59; • Alert "not in estrus" = system response between 0 and 0.29.
From this information the output membership function was built (Figure 3).
The fuzzy system was tested using a known herd response to estrus of 24,664 possible cases of estrus presence experimentally analyzed during this study.The dairy producer was trained and just the response "in estrus" could be used, and the "maybe in estrus" ignored.The combination of the response "maybe in estrus" with the response "in estrus" was ignored, because it would reduce the fuzzy system sensitivity from 94.7% to 84.2%.Thus, Table 4 shows the final results considering the response "in estrus" as a real alert for cows presenting estrus.For comparison, the results considering as real alerts of estrus and the combination of both responses were also presented: "maybe in estrus" and "in estrus".
There are two configurations of the system based on the output that may be used by farmers: (a) using a lower error rate (1.7%) the response "maybe in estrus" may be ignored and the system may be configured to use only the "in estrus" response; and (b).using both responses in order to obtain better sensitivity (94.7%) but with an added higher error (4.2%).According to Liberati and Zappavigna (2009) the use of fuzzy logic was effective in detecting general abnormal states of dairy cows.As estrus detection is normally related to some noticeable abnormality models based on fuzzy logic appears to be capable of producing warnings in advance.
The calculation of the total precision was not helpful, as it is related to the predominance of the number of cases in which the estrus is absent (responses TN and FN).The precision of the alerts "in estrus" was higher due to the small number of alerts FP.
The most relevant result was the sensitivity, which shows the capability of the system in identifying correctly the cows that are truly presenting estrus.Considering only the cows using the pedometer (84.2%) the producer would only have missed 11.9% of the estrus identification cases.The specificity of 98.3% means that in the cases in which there was no estrus the error was of Sci.Agric.(Piracicaba, Braz.), v.67, n.5, p.503-509, September/October 2010 the order of 1.7%, which infers a high degree of reliability to the developed fuzzy system, especially when comparing the systems commercially available which are just based on statistical calculations.Even though the actual estrus data are reliable because of the methodology used for data collection, some imprecision with the information about the truly occurrence of estrus is expected.It is possible that some cases identified by the model as being FP, may truly be TP.Nevertheless, a high number of estrus cases (24,664) was used in order to overcome this limitation.This result agrees with other findings in this field of knowledge.Maatje et al. (1997) found a value of sensitivity of 87% using a Kalman filter model to automatically detect estrus in dairy cows; while Eradus et al. (1998) found the value of sensitivity equals to 79% when using a fuzzy system with 24 bases of rules, and an admissible error of 6%.Firk et al. (2002) found sensitivity of 87.9% when using a data base of movement and the reference of days since last previous estrus in a herd of 373 dairy cows.
The system developed in this study allowed the response of 457 identifications of estrus among 24,664 dairy cows, while the alert of the remaining 24,207 cows was "not in estrus".The system shows errors in the false responses, FP and FN.The response FN is the worst, resulting occurred but not detected estrus, thus causing production loss.
It could as well happen that the FP indicates the false positive alert and a large number of FP alerts may induce the producer to a loss in confidence of the system.The problem found was that when trying to decrease FP automatically FN increases, which was studied in the ROC curve.It is possible to balance the systems responses FP and FN, and the found solution was the adoption of the "may be in estrus" condition.
The precise detection of estrus was reached when the cows were not using the prostaglandin hormonal therapy, which empowered the system with a good performance.This can be checked by the area below the ROC curve that is close to 1.

Conclusion
The model here developed improved the estrus detection in 28.2 % when the standard detection rate based on visual detection is 56%.Its validation in a commercial dairy farm showed that when the system was configured to use only the output response "in estrus" it was able to efficiently detect 84.2% of all true estrus cases.
When both responses "in estrus" and "maybe in estrus" were used it was able to efficiently detect 94.7% of all estrus cases.
= movement rate (steps per hour); Y = average movement rate of the last eight days (steps per hour); ΔY 8+1 = increment on movement rate (%).

Figure 1 -
Figure 1 -Schematic structure of the automatic estrus detection fuzzy system.

Figure 2 -Figure 3 -
Figure 2 -ROC curve for decision making fuzzy system where each point corresponds to a threshold value for the output value of the fuzzy logic model.

Table 1 -
Data collection potential during the period of the trial (January 15 to August 15, 2007).

Table 3 -
Rules used to build up the fuzzy inference system.

Table 4 -
Results of the fuzzy system test efficiency during six month in a commercial dairy herd.