Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
"""
Created on Mon Mar 11 13:49:40 2019
@author: Nhan Tran
"""
import numpy as np
import pandas as pd
import scipy.stats as stats
@pplonski
pplonski / churn_prediction_mljar.R
Last active September 9, 2017 20:34
Churn prediction with MLJAR and R-wrapper
# This is example, how to use MLJAR service for automatic machine learning and its R-wrapper for churn prediction.
# Example is based on data from https://github.com/WLOGSolutions/telco-customer-churn-in-r-and-h2o/tree/master/data
# Example by Dominik Krzemiński
library(mljar)
library(data.table)
# Read and clean the dataset
all_data <- fread("data/edw_cdr.csv")
all_data <- all_data[, !c("month", "year"), with = FALSE]
all_data <- all_data[complete.cases(all_data)]
@ryanpraski
ryanpraski / pageScrollDepth.R
Last active March 18, 2021 06:54
Google Analytics scroll depth tracking report using the googleAnalyticsR & tidyr package. Check out this blog post tutorial on how to use this script: http://www.ryanpraski.com/scroll-depth-tracking-analysis-with-google-analytics-r/
library(googleAnalyticsR)
library(tidyr)
#Authorized Google Analytics R- this will open a webpage
#You must be logged into your Google Analytics account on your web browser
ga_auth()
#Use the Google Analytics Management API to see a list of Google Analytics accounts you have access to
my_accounts <- google_analytics_account_list()
View(my_accounts)
PostgreSQL Data Types AWS DMS Data Types Redshift Data Types
INTEGER INT4 INT4
SMALLINT INT2 INT2
BIGINT INT8 INT8
NUMERIC (p,s) If precision is 39 or greater, then use STRING. If the scale is => 0 and =< 37 then: NUMERIC (p,s) If the scale is => 38 and =< 127 then: VARCHAR (Length)
DECIMAL(P,S) If precision is 39 or greater, then use STRING. If the scale is => 0 and =< 37 then: NUMERIC (p,s) If the scale is => 38 and =< 127 then: VARCHAR (Length)
REAL REAL4 FLOAT4
DOUBLE REAL8 FLOAT8
SMALLSERIAL INT2 INT2
SERIAL INT4 INT4
@cpard
cpard / mailchimpLogReg.py
Created July 4, 2016 11:45
Logistic Regression on email campaign data coming from Mailchimp
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 5 18:55:20 2016
@author: cpard
"""
from sqlalchemy import create_engine
import pandas as padas
import numpy as np
import statsmodels.api as sm
@chipoglesby
chipoglesby / bounding.sql
Created June 8, 2016 20:56
BigQuery's example of bounding circle to return points https://goo.gl/STb6qy
SELECT
distance, lat, long, temp
FROM
(SELECT
((ACOS(SIN(39.73756700 * PI() / 180) *
SIN((lat/1000) * PI() / 180) +
COS(39.73756700 * PI() / 180) *
COS((lat/1000) * PI() / 180) *
COS((-104.98471790 -
(long/1000)) * PI() / 180)) *
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hrbrmstr
hrbrmstr / orig.png
Last active July 16, 2023 06:43
Supreme Annotations - moar splainin here: http://rud.is/b/2016/03/16/supreme-annotations/ - NOTE: this requires the github version of ggplot2
orig.png
@henryhund
henryhund / lead_scoring_complete_query.sql
Last active July 2, 2016 16:32
This query accompanies a blog post about marketing and sales alignment and engagement lead scoring. You can find this blog post here: https://medium.com/@henryhund/traditional-lead-scoring-methods-are-expensive-and-flawed-you-can-do-better-here-s-how-584eb01f9570
WITH
/*
Find every visit
*/
all_prospects_visits AS
( SELECT DISTINCT prospects.id AS prospect_id,
activity.created_at AS visit_date,
details AS visit_details,
activity.type AS visit_type,
activity.created_at created_at
CREATE OR REPLACE FUNCTION f_findall_emails( txt VARCHAR(20000) )
RETURNS VARCHAR(20000) IMMUTABLE AS $$
"""Extract all email addresses found within a given string `txt`.
Return:
A pipe-delimited string composed of any email addresses found. (e.g. 'john@example.com|jeane@example.com|sara@example.com')
Example:
mydb=#