Skip to content

Instantly share code, notes, and snippets.

View crawles's full-sized avatar

Chris Rawles crawles

View GitHub Profile
in_training_mode = tf.placeholder(tf.bool)
hidden = tf.keras.layers.Dense(n_units,
activation=None)(X) # no activation function, yet
batch_normed = tf.keras.layers.BatchNormalization()(hidden, training=in_training_mode)
output = tf.keras.activations\
.relu(batch_normed) # ReLu is typically done after batch normalization
# optimizer code here …
extra_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
@crawles
crawles / encoding_issue.py
Created October 30, 2017 18:23
fix encoding decoding utf8 issue
import sys
reload(sys) # Reload does the trick!
sys.setdefaultencoding('UTF8')
pipeline_id: 2
model_training:
model_args:
generations: 300
population_size: 50
verbosity: 2
max_time_mins: 80
model: tpot.TPOTClassifier
extract_features:
column_id: example_id
@crawles
crawles / plpython_decorator.py
Last active February 7, 2021 06:25
Create a decorator for plpython, allowing you to create a pl/python function as you would a normal function
import inspect
import pandas.io.sql as psql
def parametrized(dec):
def layer(*args, **kwargs):
"""
Wrapper for creating plpython functions. Argument types are provided in the docstring
:param conn: Psycopg connection object
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from pyspark.sql.types import StructType
def max_time(df):
df['Time'] = pd.to_datetime(df['Time'])
return str(df.Time.max())
def apply_to_group(group_col, fxn):
# @spark_udf(IntegerType())
# def _apply_fxn(struct_col):
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" />
<title>sql_magic_API2</title><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<style type="text/css">
/*!
*
* Twitter Bootstrap
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import argparse
import threading
import pandas as pd
import pandas.io.sql as psql
from IPython.core.display import display, HTML, Image, Javascript
from IPython.core.magic import register_cell_magic, register_line_cell_magic, register_line_magic, cell_magic, magics_class
from IPython.core.magic import Magics, magics_class, cell_magic, line_magic
try:
from threading import Thread
import time
from IPython.core.display import display, HTML, Image
import sql_magic
def print_hello():
print 'hello world'
def notify_complete(del_time, return_name, return_shape):
pretty_time = time.strftime('%I:%M:%S %p %Z')