Skip to content

Instantly share code, notes, and snippets.

View guangningyu's full-sized avatar
🎯
Focusing

Guangning Yu guangningyu

🎯
Focusing
View GitHub Profile
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@guangningyu
guangningyu / random_forest.py
Created July 14, 2017 09:45
Reference: [How to Implement Random Forest From Scratch in Python](http://machinelearningmastery.com/implement-random-forest-scratch-python/)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import copy
from random import seed
from random import randrange
from math import sqrt
'''
@guangningyu
guangningyu / adaboost.py
Created July 12, 2017 15:38
Sample code of AdaBoost. Reference: Machine Learning in Action Chapter 7.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import numpy as np
def load_simple_data():
features = ([
[1. , 2.1]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@guangningyu
guangningyu / reg_tree.py
Created May 30, 2017 09:36
Sample code of regression tree. Reference: Machine Learning in Action Chapter 9.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
from numpy import mat, eye, nonzero, mean, var, shape, inf, sum, power, ones, linalg, \
corrcoef, zeros
def createDataSet(url):
'''
创建数据集,最后一列为目标变量
@guangningyu
guangningyu / text_generation_using_bigram.py
Last active March 25, 2017 09:13
根据给定语料的bigram条件概率分布,自动生成文字
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import nltk
def generate_model(cfd, word, num=15):
'''
给定条件概率分布和一个随机的词,生成一段文字
'''
for i in range(num):
@guangningyu
guangningyu / ssh_tunnel.sh
Created January 12, 2017 07:22
SSH Tunnel - Local and Remote Port Forwarding
function ssh_tunnel() {
host="[email protected]"
for port in "$@"; do
echo "> listen to port ${port}..."
# kill existing tunnel
lsof -i:"${port}" \
| awk '$0~/^ssh/{print $2}' \
| sort -u \
| xargs kill
# establish new tunnel
@guangningyu
guangningyu / logit_regression.py
Created January 3, 2017 07:36
Sample code of logistic regression. Reference: Machine Learning in Action Chapter 5.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
from numpy import mat, ones, shape, exp, array, arange
import matplotlib.pyplot as plt
def createDataSet():
features = []
labels = []
@guangningyu
guangningyu / naive_bayes.py
Created December 30, 2016 04:11
Sample code of Naive Bayes model. Reference: Machine Learning in Action Chapter 4.
#!/usr/bin/env python
import re
from numpy import ones, log
def createDataSet():
docs = [
['my', 'dog', 'has', 'flea', 'problem', 'help', 'please'],
['maybe', 'not', 'take', 'him', 'to', 'dog', 'park', 'stupid'],
['my', 'dalmation', 'is', 'so', 'cute', 'I', 'love', 'him'],
@guangningyu
guangningyu / id3_tree.py
Last active December 29, 2016 09:14
Sample code of generation ID3 decision tree. Reference: Machine Learning in Action Chapter 3
#!/usr/bin/env python
from math import log
import operator
import urllib2
def createDataSet():
'''
prepare data: the last column is the label
dataSet is like: