-
Notifications
You must be signed in to change notification settings - Fork 550
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updating anomaly check bounds to not have defaults and require inputs…
… for the bound value and isThresholdInclusive, also adding anomaly detection with extended results README, and adding anomaly detection test with 2 anomaly checks on the same suite
1 parent
0f81982
commit fdebce5
Showing
22 changed files
with
584 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
src/main/scala/com/amazon/deequ/examples/anomaly_detection_example.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...la/com/amazon/deequ/examples/anomaly_detection_with_extended_results_example.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Anomaly detection with extended results | ||
|
||
Using the `addAnomalyCheckWithExtendedResults` method instead of the original `addAnomalyCheck`method, you can get more | ||
detailed results about the anomaly detection result from the newly created metric. You can get details such as: | ||
|
||
- dataMetricValue: The metric value that is the data point. | ||
- anomalyMetricValue: The value of the metric that is being checked, which isn't always equal to the dataMetricValue. | ||
- anomalyCheckRange: The range of bounds used in the anomaly check, the anomalyMetricValue is compared to this range. | ||
- isAnomaly: If the anomalyMetricValue is outside the anomalyCheckRange, this is true. | ||
- confidence: The confidence of the anomaly detection. | ||
- detail: An optional detail message. | ||
|
||
These are contained within the AnomalyDetectionDataPoint class. | ||
```scala | ||
class AnomalyDetectionDataPoint( | ||
val dataMetricValue: Double, | ||
val anomalyMetricValue: Double, | ||
val anomalyCheckRange: BoundedRange, | ||
val isAnomaly: Boolean, | ||
val confidence: Double, | ||
val detail: Option[String]) | ||
|
||
case class BoundedRange(lowerBound: Bound, upperBound: Bound) | ||
|
||
case class Bound(value: Double, inclusive: Boolean) | ||
``` | ||
|
||
In terms of accessing the result, the AnomalyDetectionDataPoint is wrapped in an AnomalyDetectionExtendedResult class | ||
that is an optional field in the ConstraintResult class. The ConstraintResult class is a class that contains the | ||
results of a constraint check. | ||
|
||
```scala | ||
case class ConstraintResult( | ||
constraint: Constraint, | ||
status: ConstraintStatus.Value, | ||
message: Option[String] = None, | ||
metric: Option[Metric[_]] = None, | ||
anomalyDetectionExtendedResultOption: Option[AnomalyDetectionExtendedResult] = None) | ||
|
||
case class AnomalyDetectionExtendedResult(anomalyDetectionDataPoint: AnomalyDetectionDataPoint) | ||
``` | ||
|
||
|
||
In order to get extended results you need to run your verification suite with | ||
the `addAnomalyCheckWithExtendedResults` method, which has the same method signature as the original `addAnomalyCheck` | ||
method. | ||
|
||
```scala | ||
val result = VerificationSuite() | ||
.onData(yesterdaysDataset) | ||
.useRepository(metricsRepository) | ||
.saveOrAppendResult(yesterdaysKey) | ||
.addAnomalyCheckWithExtendedResults( | ||
RelativeRateOfChangeStrategy(maxRateIncrease = Some(2.0)), | ||
Size()) | ||
.run() | ||
|
||
val anomalyDetectionExtendedResult: AnomalyDetectionExtendedResult = result.checkResults.head._2.constraintResults.head | ||
.anomalyDetectionExtendedResultOption.getOrElse("placeholder to do something else") | ||
|
||
val anomalyDetectionDataPoint: AnomalyDetectionDataPoint = anomalyDetectionExtendedResult.anomalyDetectionDataPoint | ||
``` | ||
|
||
You can access the values of the anomaly detection extended results like the anomalyMetricValue and anomalyCheckRange. | ||
```scala | ||
println(s"Anomaly check range: ${anomalyDetectionDataPoint.anomalyCheckRange}") | ||
println(s"Anomaly metric value: ${anomalyDetectionDataPoint.anomalyMetricValue}") | ||
``` | ||
|
||
``` | ||
Anomaly check range: BoundedRange(Bound(-2.0,true),Bound(2.0,true)) | ||
Anomaly metric value: 4.5 | ||
``` | ||
|
||
An [executable version of this example with extended results](https://github.com/awslabs/deequ/blob/master/src/main/scala/com/amazon/deequ/examples/AnomalyDetectionWithExtendedResultsExample.scala) is available as part of our code base. |
Oops, something went wrong.