Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
2c534a09
Commit
2c534a09
authored
7 years ago
by
Simon Belak
Browse files
Options
Downloads
Patches
Plain Diff
Optimize some insights using transducer magic
parent
11b45d5c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
project.clj
+2
-0
2 additions, 0 deletions
project.clj
src/metabase/feature_extraction/insights.clj
+52
-55
52 additions, 55 deletions
src/metabase/feature_extraction/insights.clj
with
54 additions
and
55 deletions
project.clj
+
2
−
0
View file @
2c534a09
...
...
@@ -79,6 +79,8 @@
[
mysql/mysql-connector-java
"5.1.39"
]
; !!! Don't upgrade to 6.0+ yet -- that's Java 8 only !!!
[
jdistlib
"0.5.0-SNAPSHOT"
; Distribution statistic tests
:exclusions
[
com.github.wendykierp/JTransforms
]]
[
net.cgrand/xforms
"0.13.0"
; Transducer utilites
:exclusions
[
org.clojure/clojurescript
]]
[
net.sf.cssbox/cssbox
"4.12"
; HTML / CSS rendering
:exclusions
[
org.slf4j/slf4j-api
]]
[
com.clearspring.analytics/stream
"2.9.5"
; Various sketching algorithms
...
...
This diff is collapsed.
Click to expand it.
src/metabase/feature_extraction/insights.clj
+
52
−
55
View file @
2c534a09
...
...
@@ -11,6 +11,7 @@
[
histogram
:as
h
]
[
math
:as
math
]
[
timeseries
:as
ts
]]
[
net.cgrand.xforms
:as
x
]
[
redux.core
:as
redux
]))
(
defmacro
^
:private
definsight
...
...
@@ -82,42 +83,36 @@
https://en.wikipedia.org/wiki/Variance"
[
resolution
series
]
(
when
resolution
(
->>
series
(
partition
(
ts/period-length
resolution
)
1
)
(
transduce
(
map-indexed
(
fn
[
i
xsi
]
[
i
(
transduce
(
map
second
)
(
redux/post-complete
h/histogram
(
fn
[
histogram
]
(
/
(
h.impl/variance
histogram
)
(
h.impl/mean
histogram
))))
xsi
)]))
(
redux/post-complete
(
redux/juxt
(
stats/sum-squares
first
second
)
(
redux/fuse
{
:s-x
(
redux/pre-step
+
first
)
:s-xx
(
redux/pre-step
+
(
comp
sq
first
))
:s-y
(
redux/pre-step
+
second
)
:s-yy
(
redux/pre-step
+
(
comp
sq
second
))}))
(
fn
[[{
:keys
[
ss-xy
ss-x
n
]}
{
:keys
[
s-x
s-xx
s-y
s-yy
]}]]
(
when
(
and
(
>
n
2
)
(
not-any?
zero?
[
ss-x
s-x
]))
(
let
[
slope
(
/
ss-xy
ss-x
)
slope-error
(
*
(
/
1
(
-
n
2
)
(
-
(
*
n
s-xx
)
(
sq
s-x
)))
(
-
(
*
n
s-yy
)
(
sq
s-y
)
(
*
(
sq
slope
)
(
-
(
*
n
s-xx
)
(
sq
s-x
)))))]
(
when
(
and
(
not=
slope
0
)
(
math/significant?
(
/
slope
slope-error
)
(
d/t-distribution
(
-
n
2
))
(
/
0.05
2
)))
{
:mode
(
if
(
pos?
slope
)
:increasing
:decreasing
)})))))))))
(
transduce
(
comp
(
x/partition
(
ts/period-length
resolution
)
1
(
comp
(
map
second
)
(
x/reduce
h/histogram
)))
(
map-indexed
(
fn
[
idx
histogram
]
[(
double
idx
)
(
/
(
h.impl/variance
histogram
)
(
h.impl/mean
histogram
))])))
(
redux/post-complete
(
redux/juxt
(
stats/sum-squares
first
second
)
(
redux/fuse
{
:s-x
(
redux/pre-step
+
first
)
:s-xx
(
redux/pre-step
+
(
comp
sq
first
))
:s-y
(
redux/pre-step
+
second
)
:s-yy
(
redux/pre-step
+
(
comp
sq
second
))}))
(
fn
[[{
:keys
[
ss-xy
ss-x
n
]}
{
:keys
[
s-x
s-xx
s-y
s-yy
]}]]
(
when
(
and
(
>
n
2
)
(
not-any?
zero?
[
ss-x
s-x
]))
(
let
[
slope
(
/
ss-xy
ss-x
)
slope-error
(
/
(
-
(
*
n
s-yy
)
(
sq
s-y
)
(
*
(
sq
slope
)
(
-
(
*
n
s-xx
)
(
sq
s-x
))))
(
-
n
2
)
(
-
(
*
n
s-xx
)
(
sq
s-x
)))]
(
when
(
and
(
not=
slope
0
)
(
math/significant?
(
/
slope
slope-error
)
(
d/t-distribution
(
-
n
2
))
(
/
0.05
2
)))
{
:mode
(
if
(
pos?
slope
)
:increasing
:decreasing
)})))))
series
)))
(
definsight
seasonality
"Is there a seasonal component to the changes in data?
...
...
@@ -189,26 +184,28 @@
https://en.wikipedia.org/wiki/Stationary_process"
[
series
resolution
]
(
when-let
[
n
(
ts/period-length
resolution
)]
(
->>
series
(
partition
n
1
)
(
map
(
partial
transduce
(
map
second
)
h/histogram
))
(
partition
2
1
)
(
map
(
fn
[[
h1
h2
]]
(
let
[
mean1
(
h.impl/mean
h1
)
mean2
(
h.impl/mean
h2
)
variance1
(
h.impl/variance
h1
)
variance2
(
h.impl/variance
h2
)]
(
if
(
=
variance1
variance2
0
)
false
(
transduce
(
comp
(
x/partition
n
1
(
comp
(
map
second
)
(
x/reduce
h/histogram
)))
(
map
(
fn
[
histogram
]
{
:mean
(
h.impl/mean
histogram
)
:var
(
h.impl/variance
histogram
)}))
(
x/partition
2
1
(
x/into
[])))
(
fn
([]
true
)
([
acc
]
acc
)
([
_
[{
mean1
:mean
var1
:var
}
{
mean2
:mean
var2
:var
}]]
(
if
(
=
var1
var2
0
)
true
(
let
[
t
(
/
(
-
mean1
mean2
)
(
num/sqrt
(
/
(
+
variance1
variance2
)
n
)))
k
(
num/round
(
/
(
sq
(
/
(
+
variance1
variance2
)
n
))
(
/
(
+
(
sq
variance1
)
(
sq
variance2
))
(
*
n
(
-
n
1
)))))]
(
math/significant?
t
(
d/t-distribution
k
)
(
/
0.05
2
)))))))
(
every?
false?
))))
(
num/sqrt
(
/
(
+
var1
var2
)
n
)))
k
(
num/round
(
/
(
sq
(
/
(
+
var1
var2
)
n
))
(
/
(
+
(
sq
var1
)
(
sq
var2
))
(
*
n
(
-
n
1
)))))]
(
if
(
math/significant?
t
(
d/t-distribution
k
)
(
/
0.05
2
))
(
reduced
false
)
true
)))))
series
)))
(
definsight
trend
"What is the best (simple) trend model?
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment