Skip to content

Instantly share code, notes, and snippets.

@orcaman
orcaman / metrics.py
Created July 21, 2019 16:00
metrics.py
from sklearn.metrics import recall_score, precision_score, roc_auc_score
def recall(preds, dtrain):
labels = dtrain.get_label()
return 'recall', recall_score(labels, np.round(preds))
def precision(preds, dtrain):
labels = dtrain.get_label()
return 'precision', precision_score(labels, np.round(preds))
for _, d := range p.DatasetDescriptors {
for _, t := range d.TableDescriptors {
wg.Add(1)
go func(d *datasetDescriptor, t *tableDescriptor) {
rl.Take()
defer wg.Done()
schemaPath := *backupPath + "/" + d.Name + "/" + t.Name + "/schema.json"
if fileExists(ctx, schemaPath, bkt) {
return
go func() {
wg.Wait()
donec <- true
}()
errorCount := 0
for {
select {
case err := <-errc:
if errorCount >= *maxErrors {
WITH
Distances AS (
SELECT
DISTINCT ML.CENTROID_ID,
sepal_length,
sepal_width,
petal_length,
petal_width,
species,
MIN(NEAREST_CENTROIDS_DISTANCE.DISTANCE) AS distance_from_closest_centroid
@orcaman
orcaman / APPROX_QUANTILES.sql
Created June 26, 2019 20:20
APPROX_QUANTILES
Threshold AS (
SELECT
ROUND(APPROX_QUANTILES(distance_from_closest_centroid,10000)[
OFFSET
(9500)],2) AS threshold
FROM
Distances)
@orcaman
orcaman / distnaces.sql
Created June 26, 2019 20:08
distnaces.sql
WITH
Distances AS (
SELECT
DISTINCT ML.CENTROID_ID,
sepal_length,
sepal_width,
petal_length,
petal_width,
species,
MIN(NEAREST_CENTROIDS_DISTANCE.DISTANCE) AS distance_from_closest_centroid
@orcaman
orcaman / K-Means CREATE OR REPLACE MODEL.sql
Last active June 26, 2019 19:59
K-Means CREATE OR REPLACE MODEL
CREATE OR REPLACE MODEL
 public.iris_clusters
OPTIONS
 (model_type='kmeans',
num_clusters=4,
 standardize_features = TRUE) AS
SELECT
 DISTINCT sepal_length,
 sepal_width,
 petal_length,
@orcaman
orcaman / stations.csv
Created February 9, 2019 20:11
NOAA Station Numbers Mapped to Address, City, State, County and Zipcode (US only) Using Reverse Geocoding
We can't make this file beautiful and searchable because it's too large.
StationNumber,Lat,Lon,Address,State,City,County,Zip
690014,32.350000,-106.367000,"Unnamed Road, Chaparral, NM 88081, USA",NM,Chaparral,Otero County,88081
690070,36.683000,-121.767000,"721 Neeson Rd, Marina, CA 93933, USA",CA,Marina,Monterey County,93933
690020,36.000000,-121.233000,"7th Division Rd, Jolon, CA 93928, USA",CA,Jolon,Monterey County,93928
690020,36.000000,-121.233000,"7th Division Rd, Jolon, CA 93928, USA",CA,Jolon,Monterey County,93928
690110,42.608000,-82.835000,"Selfridge Angb Airport, Harrison Charter Township, MI 48045, USA",MI,Harrison charter Township,Macomb County,48045
690140,33.667000,-117.733000,"8065 Marine Way, Irvine, CA 92618, USA",CA,Irvine,Orange County,92618
690150,34.300000,-116.167000,"Rainbow Canyon Road, Twentynine Palms, CA 92277, USA",CA,Twentynine Palms,San Bernardino County,92277
690169,33.700000,-117.830000,"2437 Park Ave, Tustin, CA 92782, USA",CA,Tustin,Orange County,92782
690174,36.533000,-115.567000,"US-95, Nevada, USA",NV,,Clark County,
@orcaman
orcaman / main.go
Created February 9, 2019 13:51
Reverse Geocode NOAA station coordinates
package main
import (
"context"
"encoding/csv"
"fmt"
"log"
"os"
"sync"
"time"
@orcaman
orcaman / btc_sent.sql
Created January 1, 2019 07:13
How Many Bitcoins Were Sent Per Month Per Year
#standardSQL
SELECT
EXTRACT(year
FROM
o.day) AS year,
EXTRACT(month
FROM
o.day) AS month,
SUM(o.output_satoshis) * 0.00000001 AS btc
FROM (