Skip to content

Instantly share code, notes, and snippets.

View huseinzol05's full-sized avatar
🍵
Hunting cendol!

HUSEIN ZOLKEPLI huseinzol05

🍵
Hunting cendol!
View GitHub Profile
@huseinzol05
huseinzol05 / download.py
Created January 12, 2018 08:19
download historical commodities (crude oil, gold, kerosene, propane, natural gas, heating oil, gasoline)
import urllib
print 'downloading crude oil data'
urllib.urlretrieve("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&height=450&stacking=&range=1yr&mode=fred&id=DCOILWTICO&transformation=lin&nd=1986-01-02&ost=-99999&oet=99999&lsv=&lev=&mma=0&fml=a&fgst=lin&fgsnd=2009-06-01&fq=Daily&fam=avg&vintage_date=&revision_date=&line_color=%234572a7&line_style=solid&lw=2&scale=left&mark_type=none&mw=2&width=1168", "crude-oil.csv")
print 'downloading diesel data'
urllib.urlretrieve("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&drp=0&cosd=2017-01-08&coed=2018-01-08&height=450&stacking=&range=1yr&mode=fred&id=DDFUELUSGULF&transformation=lin&nd=2006-06-14&ost=-99999&oet=99999&lsv=&lev=&
@huseinzol05
huseinzol05 / stack.py
Last active January 12, 2018 09:19
simple-stack multivariate model regression
import numpy as np
from sklearn.ensemble import *
import xgboost as xgb
from sklearn.cross_validation import train_test_split
X = np.random.uniform(size=(100,10))
Y = np.random.uniform(size=(100))
# split our dataset for validation
train_X, test_X, train_Y, test_Y = train_test_split(X, Y, test_size = 0.2)
@huseinzol05
huseinzol05 / featuring.py
Created January 13, 2018 05:42
concat sound features using speechpy
import speechpy
import scipy.io.wavfile as wav
import numpy as np
def extract_features(signal, fs):
frames = speechpy.processing.stack_frames(signal, sampling_frequency=fs, frame_length=0.020, frame_stride=0.01, filter=lambda x: np.ones((x,)),zero_padding=True)
power_spectrum = speechpy.processing.power_spectrum(frames, fft_points=1)
logenergy = speechpy.feature.lmfe(signal, sampling_frequency=fs, frame_length=0.020, frame_stride=0.01,num_filters=1, fft_length=512, low_frequency=0, high_frequency=None)
mfcc = speechpy.feature.mfcc(signal, sampling_frequency=fs, frame_length=0.020, frame_stride=0.01,num_filters=1, fft_length=512, low_frequency=0, high_frequency=None)
mfcc_cmvn = speechpy.processing.cmvnw(mfcc,win_size=301,variance_normalization=True)
@huseinzol05
huseinzol05 / bar-with-label.py
Created January 13, 2018 09:34
matplotlib nice bar plot with label
x = np.random.randint(0, 100, size=(100))
rects1=plt.bar(np.arange(x.shape[0]), x)
def autolabel(rects):
(y_bottom, y_top) = plt.ylim()
y_height = y_top - y_bottom
for rect in rects:
height = rect.get_height()
p_height = (height / y_height)
if p_height > 0.95:
label_position = height - (y_height * 0.05)
@huseinzol05
huseinzol05 / session.py
Last active January 14, 2018 03:22
initiate 2 graphs and sessions in Tensorflow
import numpy as np
import tensorflow as tf
class Feed_forward:
def __init__(self, input_dimension):
self.X = tf.placeholder(tf.float32, [None, input_dimension])
self.Y = tf.placeholder(tf.float32, [None, 1])
hidden_layer = tf.Variable(tf.random_uniform([input_dimension, 1], -1.0, 1.0))
logits = tf.matmul(self.X, hidden_layer)
self.cost = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits = logits, labels = self.Y))
@huseinzol05
huseinzol05 / copy-weight.py
Created February 16, 2018 09:25
copy tensorflow model weights to another tensorflow model weights
import numpy as np
import tensorflow as tf
class Model:
def __init__(self):
def conv_layer(x, conv, stride = 1):
return tf.nn.conv2d(x, conv, [1, stride, stride, 1], padding = 'SAME')
def pooling(x, k = 2, stride = 2):
return tf.nn.max_pool(x, ksize = [1, k, k, 1], strides = [1, stride, stride, 1], padding = 'SAME')
self.X = tf.placeholder(tf.float32, [None, 80, 80, 4])
@huseinzol05
huseinzol05 / simple-conv2d.ipynb
Created February 18, 2018 03:29
convolution-2d
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@huseinzol05
huseinzol05 / simple-atrous2d.ipynb
Last active February 18, 2018 03:45
implement atrous2d using numpy
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@huseinzol05
huseinzol05 / activation-function.ipynb
Created February 19, 2018 10:53
activation functions with first derivative
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@huseinzol05
huseinzol05 / iris-mlp-softmax-crossentropy-numpy.ipynb
Last active October 4, 2018 20:31
implement 3 hidden layer feed-forward with softmax and cross-entropy for Iris dataset
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.