Skip to content

Instantly share code, notes, and snippets.

View myui's full-sized avatar

Makoto YUI myui

View GitHub Profile
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)
package puzzle;
import java.util.LinkedList;
import java.util.Queue;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.google.common.base.Preconditions;
@myui
myui / bprmf.md
Last active March 12, 2018 07:06
use movielens;

select max(movieid) from ratings;
> 3952

-- list popular items
WITH t as (
  select 
    movieid as itemid,
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0