Skip to content

Instantly share code, notes, and snippets.

@borgwang
borgwang / quantile_regression.ipynb
Last active April 12, 2024 09:28
quantile_regression
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@borgwang
borgwang / raw_nn.py
Last active June 14, 2020 18:43
backpropagation with numpy
import numpy as np
from sklearn.datasets import load_iris
def softmax(inputs):
return np.exp(inputs) / np.sum(np.exp(inputs), 1)[:, None]
def construct_net(in_dim, out_dim, hidden_dim=20):
bound1 = np.sqrt(6.0 / (in_dim + hidden_dim))
@borgwang
borgwang / trie_tree.py
Last active August 17, 2017 16:53
trie tree demo
class TrieNode(object):
def __init__(self):
self.children = dict()
self.is_word = False
class TrieTree(object):
def __init__(self):
import numpy as np
import matplotlib.pyplot as plt
data = [[1.658985, 4.285136], [-3.453687, 3.424321], [4.838138, -1.151539],
[-5.37971, -3.362104], [0.972564, 2.924086], [-3.567919, 1.531611],
[0.450614, -3.302219], [-3.487105, -1.724432], [2.668759, 1.594842],
[-3.15648, 3.191137], [3.165506, -3.999838], [-2.786837, -3.099354],
[4.208187, 2.984927], [-2.123337, 2.943366], [0.704199, -0.479481],
[-0.392370, -3.963704], [2.831667, 1.574018], [-0.790153, 3.343144],
[2.943496, -3.357075], [-3.195883, -2.283926], [2.336445, 2.875106],
from __future__ import division
import csv
import numpy as np
import random
import tensorflow as tf
# data prepare
X, y = [], []
@borgwang
borgwang / pca.py
Last active August 17, 2017 16:52
PCA (eig and svd approach)
import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
def eig_decomposition(img, p=0.9):
A = np.array(img, dtype=float)
mean_A = np.mean(A)
A -= mean_A
# calculate covarience matrix