Skip to content

Instantly share code, notes, and snippets.

View myui's full-sized avatar

Makoto YUI myui

View GitHub Profile
WITH tmp1 as (
select
userid,
array[
probabilities[1],
probabilities[2],
probabilities[3],
probabilities[4],
probabilities[5],
probabilities[6],
CREATE TABLE users (
rowid int, name string, age int, gender string
);
INSERT INTO users VALUES
(1, 'Jacob', 20, 'Male'),
(2, 'Mason', 22, 'Male'),
(3, 'Sophia', 35, 'Female'),
(4, 'Ethan', 55, 'Male'),
(5, 'Emma', 15, 'Female'),
(6, 'Noah', 46, 'Male'),
set my_coment to "#" --コメント文字
tell application "mi"
tell document 1
set p_count to (count paragraphs of selection object 1)
set start_p to index of paragraph 1 of selection object 1
set end_p to start_p + p_count - 1
repeat with i from start_p to end_p
set tmp_str to quoted form of (paragraph i as Unicode text)
with tmp as (
select
-- group by is sometimes faster than distinct
-- distinct extract_feature(feature) as feature
extract_feature(feature) as feature
from
test l
lateral view explode(features) r as feature
),
mapped as (
@myui
myui / libsvm.sql
Last active August 14, 2019 06:33
SELECT
-- conversion for libsvm format
label || ' ' || array_join(array_sort(
feature_hashing(features),
(x, y) -> if(cast(substr(x, 1, strpos(x, ':') - 1) as bigint) < cast(substr(y, 1, strpos(y, ':') - 1) as bigint),
-1,
if(substr(x, 1, strpos(x, ':') - 1) = substr(y, 1, strpos(y, ':') - 1), 0, 1)
)
), ' ') as line
from
SELECT
from_json(to_json(
ARRAY(
NAMED_STRUCT("country", "japan", "city", "tokyo"),
NAMED_STRUCT("country", "japan", "city", "osaka")
)
),'array<struct<city:string>>');
select madlib.logregr_train( source_table,
out_table,
features
);
create table model 
as
select 
 feature,
 voted_avg(weight) as weight
from 
 (select 
     -- hinge loss by the default
     train_classifier(add_bias(features),label,'-iter 20') as (feature,weight)