Business intelligence made simple
Added Prophet anomaly detection
Andrew Kane3395c5d58b21
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 354d73f2..b2f19faa 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1,5 +1,6 @@## 2.4.3 (unreleased)+- Added Prophet anomaly detection- Fixed style for new select items## 2.4.2 (2021-02-08)diff --git a/README.md b/README.mdindex 1210e996..12a753ea 100644--- a/README.md+++ b/README.md@@ -416,11 +416,25 @@ This feature requires PostgreSQL or MySQL.## Anomaly Detection-Blazer supports two different approaches to anomaly detection.+Blazer supports three different approaches to anomaly detection.++### Prophet [master]++Add [prophet](https://github.com/ankane/prophet) to your Gemfile:++```ruby+gem 'prophet-rb'+```++And add to `config/blazer.yml`:++```yml+anomaly_checks: prophet+```### Trend-[Trend](https://trendapi.org/) is easiest to set up. By default, it uses an external service, but you can run it on your own infrastructure as well.+[Trend](https://trendapi.org/) uses an external service by default, but you can run it on your own infrastructure as well.Add [trend](https://github.com/ankane/trend) to your Gemfile:diff --git a/lib/blazer/result.rb b/lib/blazer/result.rbindex 0a5e7253..dba47026 100644--- a/lib/blazer/result.rb+++ b/lib/blazer/result.rb@@ -174,7 +174,18 @@ module Blazerdef anomaly?(series)series = series.reject { |v| v[0].nil? }.sort_by { |v| v[0] }- if Blazer.anomaly_checks == "trend"+ case Blazer.anomaly_checks+ when "prophet"+ df = Rover::DataFrame.new(series[0..-2].map { |v| {"ds" => v[0], "y" => v[1]} })+ m = Prophet.new(interval_width: 0.99)+ m.fit(df)+ future = Rover::DataFrame.new(series[-1..-1].map { |v| {"ds" => v[0]} })+ forecast = m.predict(future)+ lower = forecast.to_a[0]["yhat_lower"]+ upper = forecast.to_a[0]["yhat_upper"]+ value = series.last[1]+ value < lower || value > upper+ when "trend"anomalies = Trend.anomalies(Hash[series])anomalies.include?(series.last[0])elsediff --git a/lib/generators/blazer/templates/config.yml.tt b/lib/generators/blazer/templates/config.yml.ttindex 65230e65..eddde94e 100644--- a/lib/generators/blazer/templates/config.yml.tt+++ b/lib/generators/blazer/templates/config.yml.tt@@ -63,11 +63,11 @@ check_schedules:# enable anomaly detection# note: with trend, time series are sent to https://trendapi.org-# anomaly_checks: trend / r+# anomaly_checks: prophet / trend / r# enable forecasting# note: with trend, time series are sent to https://trendapi.org-# forecasting: trend / prophet+# forecasting: prophet / trend# enable map# mapbox_access_token: <%%= ENV["MAPBOX_ACCESS_TOKEN"] %>