Skip to content

Instantly share code, notes, and snippets.

@mkowoods
mkowoods / bulk-delete.sql
Last active July 29, 2019 12:55
Bulk Delete of SQL Rows
-- https://stackoverflow.com/a/28324562
-- https://sqlperformance.com/2013/03/io-subsystem/chunk-deletes
DECLARE @Deleted_Rows INT;
SET @Deleted_Rows = 1;
WHILE (@Deleted_Rows > 0)
BEGIN
BEGIN TRANSACTION
@mkowoods
mkowoods / tmp.sql
Created July 9, 2019 11:27
Notes for Will Buy on Return visit
Source Data Set: https://console.cloud.google.com/bigquery?p=data-to-insights&d=ecommerce&t=web_analytics&page=table
## TRAIN
CREATE OR REPLACE MODEL `ecommerce.classification_model_2`
OPTIONS
(model_type='logistic_reg', labels = ['will_buy_on_return_visit']) AS
WITH all_visitor_stats AS (
@mkowoods
mkowoods / google_drive_io.py
Created March 5, 2018 23:49
Snippet for Importing/Exporting data from google colab to google drive
#snippet for getting data to and from google drive while using google colab
!pip install -q tqdm
import tqdm
from google.colab import auth
from googleapiclient.discovery import build
import io
from googleapiclient.http import MediaIoBaseDownload
from googleapiclient.http import MediaFileUpload
@mkowoods
mkowoods / server.sql
Last active August 22, 2017 22:25
useful sql server sys queries
--last mod date for all tables
SELECT
t.name,
t.modify_date,
i.rowcnt
FROM sys.tables t
left outer join sysindexes i
ON t.object_id = i.id
WHERE i.indid < 2
@mkowoods
mkowoods / cartpole_solution.py
Last active December 31, 2016 19:55
Solution for both CartPoleTasks
""""
uses policy/value iteration to solve the task
there's a 2 layer neural network that's responsible for estimating the future value of a state
and a linear weight model (wrapped in a softmax) to handle selecting the policy(acitons)
the policy model incorporates the value function, by adjusting the loss score by the difference between the observed reward and the expected reward
actions that perform much better than expected will have a lower "penalty" and thus have their weights less affected than actions where the
observed performance is much worse.
The other interesting component of this model is the exploration function, which ensures that the agent explores at a rate that's proportional
@mkowoods
mkowoods / rl_table_taxi.py
Created December 12, 2016 21:07
Model parameters used to train the Taxi Algorithm
import numpy as np
import gym
"""
Solved Frozen Lake: after 1100 steps.
Solved Taxi-v1: after 500 steps
Implementation of SARSA...
@mkowoods
mkowoods / rl_table.py
Last active December 12, 2016 20:07
Implementation of SARSA
import numpy as np
import gym
"""
Implementation of SARSA...
Using a relatively small learning rate, which causes convergence to take longer
Built as an object to allow for easy extensibility to other environments for quick benchmarking
import os
os.chdir('/Users/mwoods/Desktop')
# -----------------
# User Instructions
#
# Finite State Machine
# An Example of Finite State Machine Using Classes
# Responsed to: https://www.reddit.com/r/dailyprogrammer/comments/4cb7eh
class FiniteStateMachine:
def __init__(self):
self.states = set([])
self.transitions = {}
self.current_state = None
@mkowoods
mkowoods / map_reduce_sorting.py
Last active June 20, 2019 19:14
An example of how to use map reduce logic to sort a file that is greater than the size of memorey
import random
import os
random.seed(42)
F_PATH = "data.csv"
OUTPUT_PATH_TEMPLATE = "tmp_%d.csv"
CHUNK_SIZE = 5