This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function(...) { | |
Reduce(function(x, y) { | |
i <- which(is.na(x)) | |
x[i] <- y[i] | |
x}, | |
list(...)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\begin{table}[htb] | |
\ttabbox{ \caption{ caption} | |
\label{label}}{ | |
\begin{tabular}{lrrrrr} | |
\end{tabular} | |
} | |
\end{table} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
msk=dat.apply(pd.isnull).apply(sum,1)<=0 | |
dat.loc[msk,:] | |
# to drop missing values by cols: | |
msk=dat.apply(pd.isnull).apply(sum,0)<=0 | |
dat.loc[:,msk] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fredapi as fred | |
import pandas | |
import matplotlib.pyplot as plt | |
apikey=open("/Users/j1trc01/.fred_api_key",'r').read() | |
Fred=fred.Fred(apikey) | |
gdpnow=Fred.get_series("GDPNOW") | |
gdp=Fred.get_series("A191RL1Q225SBEA") | |
dat=pd.DataFrame({'gdpnow':gdpnow,'gdp':gdp}) | |
dat['error']=abs(dat['gdpnow']-dat['gdp']) | |
plt.plot(dat.error,c='r') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow.contrib.learn as learn | |
from tensorflow.contrib.learn.python.learn.estimators import model_fn as model_fn_lib | |
import tensorflow as tf | |
import tensorflow.contrib.slim as sm | |
import numpy as np | |
import functools | |
import matplotlib.pyplot as plt | |
def build_toy_dataset(N=40, noise_std=0.1): | |
D = 6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow.contrib.learn as learn | |
from tensorflow.contrib.learn.python.learn.estimators import model_fn as model_fn_lib | |
import tensorflow as tf | |
import tensorflow.contrib.slim as sm | |
import numpy as np | |
import functools | |
def build_toy_dataset(N=40, noise_std=0.1): | |
D = 1 | |
x = np.concatenate([np.linspace(0, 2, num=N / 2), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# to get expand-grid like functionality in python 3 | |
# from http://stackoverflow.com/questions/12864445/numpy-meshgrid-points | |
import numpy as np | |
def expandgrid(*arrs): | |
arrs = tuple(reversed(arrs)) | |
lens =[i for i in map(len, arrs)] | |
dim = len(arrs) | |
sz = 1 | |
for s in lens: | |
sz *= s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pass column as string into data.table programatically | |
tmp<-function(x="col"){ | |
x =eval(substitute(as.name(x))) | |
dt[is.na(eval(x))==F,eval(x)] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# first, if not done already, enable atrun daemon. | |
# need to set: | |
# sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.atrun.plist | |
#Something like this into terminal | |
echo osascript -e \'tell application \"System Events\" \' -e \'keystroke \"q\" using command down\' -e \'end tell\'|at now + 1 minute |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/zsh | |
docker rm $(docker ps -a|grep -oe '^\w*') |