Skip to content

Instantly share code, notes, and snippets.

@myui
Created July 3, 2019 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myui/2a9bfa78002eba116c07623ec9f6afaf to your computer and use it in GitHub Desktop.
Save myui/2a9bfa78002eba116c07623ec9f6afaf to your computer and use it in GitHub Desktop.
WITH tmp1 as (
select
userid,
array[
probabilities[1],
probabilities[2],
probabilities[3],
probabilities[4],
probabilities[5],
probabilities[6],
probabilities[7],
probabilities[8] * 0.8 -- M3
] as probabilities
from
rf_predicted_cv
),
tmp2 as (
select
userid,
probabilities,
reduce(
probabilities,
CAST(ROW(-infinity(), 0, 0) AS ROW(max DOUBLE, index INTEGER, argmax INTEGER)),
(s, x) -> CAST(ROW(if(x > s.max, x, s.max), s.index + 1, if(x > s.max, s.index, s.argmax)) AS ROW(max DOUBLE, index INTEGER, argmax INTEGER)),
s -> s.argmax
) as label
from
tmp1
)
select
l.userid,
l.probabilities,
r.label
from
tmp2 l
JOIN label_mapping r ON (l.label = r.label_id)
limit 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment