Skip to content

Instantly share code, notes, and snippets.

View ks--ks's full-sized avatar
🎯
Focusing

Olga Berezovsky ks--ks

🎯
Focusing
View GitHub Profile
@ks--ks
ks--ks / example1.R
Created November 4, 2016 23:20
Code snippets for _____
data(mushroom)
X = mushroom[, -1]
y = as.numeric(mushroom[, 1]) # конвертировать метки в числа
WITH actions AS
(
SELECT ca.created_at::date as actdate,
COUNT(*) AS act,
CASE when ca.state IN ('CA', 'WA', 'DC', 'NY', 'IL') THEN ca.state ELSE 'other' END AS state,
CASE WHEN ca.current_medium IN ('source1', 'source2', 'source3') THEN ca.current_medium ELSE 'other' END AS source,
lower('id-' || ca.created_at::date ||
'-' || CASE when ca.state IN ('CA', 'WA', 'DC', 'NY', 'IL') THEN ca.state ELSE 'other' END ||
'-' || CASE WHEN ca.current_medium IN ('source1', 'source2', 'source3') THEN ca.current_medium ELSE 'other' END
) AS id
action_view as
(
SELECT created_at::date AS viewdate,
COUNT(av.userid) AS act_v,
CASE when av.state IN ('CA', 'WA', 'DC', 'NY', 'IL') THEN av.state ELSE 'other' END AS state,
CASE WHEN av.current_medium IN ('source1', 'source2', 'source3') THEN av.current_medium ELSE 'other' END AS source,
lower('id-' || av.created_at::date ||
'-' || CASE when av.state IN ('CA', 'WA', 'DC', 'NY', 'IL') THEN av.state ELSE 'other' END ||
'-' || CASE WHEN av.current_medium IN ('source1', 'source2', 'source3') THEN av.current_medium ELSE 'other' END
) AS idp
SELECT av.sapdate AS date,
lower(av.state) AS state,
lower(av.source) AS source,
av.act_v AS act_view,
a.act::int AS act,
FROM action_view av
LEFT OUTER JOIN actions a ON av.idp = a.id
ORDER BY date;
@ks--ks
ks--ks / ActionShares.sql
Created January 11, 2019 04:17
PowerUser_Step1
WITH
recruits AS (
SELECT recruiter_id AS user_id
, item_name
, COUNT(DISTINCT recruited_id) AS recruits
FROM recruit_table
WHERE created_at::DATE BETWEEN '2017-01-01'-180 AND '2017-01-08'
GROUP BY 1, 2
)
@ks--ks
ks--ks / InfluenceScore.sql
Created January 11, 2019 04:20
PowerUser_Step2
, influence AS (
SELECT user_id
, recruit_score
, share_score
, days_share_score
, channel_share_score
, NTILE(100) OVER (ORDER BY recruit_score DESC, share_score DESC, days_share_score DESC, channel_share_score DESC)
FROM (
SELECT a.user_id
@ks--ks
ks--ks / ntile.sql
Last active January 11, 2019 04:31
PowerUser_Step3
, NTILE(100) OVER (ORDER BY recruit_score DESC, share_score DESC, days_share_score DESC, channel_share_score DESC)
@ks--ks
ks--ks / Pandas EDA.py
Created May 17, 2020 04:41
Blog article code
import numpy as np #linear algebra
import pandas as pd #data processing
import seaborn as sns #statistical graph package
import matplotlib.pyplot as plt #plot package for visualisations
import pandasql as ps #sql package
#plt.style.use('bmh') #setting up 'bmh' as "Bayesian Methods for Hackers" style sheet
plt.style.use('ggplot') #R ggplot style
print(plt.style.available)