Skip to content

Instantly share code, notes, and snippets.

@zaxcie
zaxcie / google_finance_intraday.py
Created August 14, 2018 01:35 — forked from lebedov/google_finance_intraday.py
Retrieve intraday stock data from Google Finance.
#!/usr/bin/env python
"""
Retrieve intraday stock data from Google Finance.
"""
import csv
import datetime
import re
import pandas as pd
@zaxcie
zaxcie / append_variable_to_url.py
Created June 2, 2018 17:23
Add variable to URL
def append_variable_to_url(URL, var_dict):
'''
Properly format string to append variable to URL
:param var_dict:
:return: URL variables string
'''
var_string = ""
for key in var_dict:
if var_string == "":
@zaxcie
zaxcie / req_jupyter.py
Last active March 27, 2018 01:28
Requirements for jupyter
%load_ext autoreload
%autoreload 2
%matplotlib inline
@zaxcie
zaxcie / Find_Optimal_Cutoff.py
Created January 21, 2018 05:01
Find the cut off point of a binary classification python
def Find_Optimal_Cutoff(target, predicted):
""" Find the optimal probability cutoff point for a classification model related to event rate
Parameters
----------
target : Matrix with dependent or target data, where rows are observations
predicted : Matrix with predicted data, where rows are observations
Returns
-------
@zaxcie
zaxcie / NbSvmClassifier.py
Created January 18, 2018 02:48
NbSvmClassifier SKlearn implementation
from sklearn.base import BaseEstimator, ClassifierMixin
from sklearn.utils.validation import check_X_y, check_is_fitted
from sklearn.linear_model import LogisticRegression
from scipy import sparse
class NbSvmClassifier(BaseEstimator, ClassifierMixin):
def __init__(self, C=1.0, dual=False, n_jobs=1):
self.C = C
self.dual = dual
self.n_jobs = n_jobs
@zaxcie
zaxcie / attention_rnn_keras.py
Created January 16, 2018 17:19
Attention layer for an RNN (LSTM, GRU or simple RNN) in Keras
class Attention(Layer):
def __init__(self, step_dim,
W_regularizer=None, b_regularizer=None,
W_constraint=None, b_constraint=None,
bias=True, **kwargs):
"""
Keras Layer that implements an Attention mechanism for temporal data.
Supports Masking.
Follows the work of Raffel et al. [https://arxiv.org/abs/1512.08756]
# Input shape
@zaxcie
zaxcie / generate_cache.py
Last active December 21, 2017 04:52
Recursivly generate a cache of SHA256 of a folder
import os
import hashlib
def generate_cache_recursive(path, cache):
'''Recursivly generate the cache of files in path. SHA256 is used.
path - string that is the path os a folder
cache - set that is the cache
du -a | cut -d/ -f2 | sort | uniq -c | sort -nr