Skip to content

Instantly share code, notes, and snippets.

import pandas as pd
import numpy as np
# Model
class SingleHiddenBP:
input_number = 0
hidden_number = 0
output_number = 0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zhenghaoz
zhenghaoz / logistic_regression.py
Created November 6, 2017 06:14
Logistic Regression with Kernel
import matplotlib.colors as colors
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
class LogisticRegression:
kern_param = 0
X = np.array([])
a = np.array([])
@zhenghaoz
zhenghaoz / k_means.py
Created November 1, 2017 02:40
K Means Algorithm Implementation
import matplotlib.pyplot as plt
import numpy as np
from scipy.spatial import ConvexHull
class KMeans:
mean_vec = np.array([])
X = np.array([])
y = np.array([])
clusters = []
@zhenghaoz
zhenghaoz / bagging.py
Created October 29, 2017 06:16
Bagging Algorithm Implementation
import copy
import numpy as np
class Bagging:
num_base = 0
classifiers = []
minvs = []
maxvs = []
@zhenghaoz
zhenghaoz / decision_tree.py
Last active November 14, 2017 01:44
Decision Tree Implementation
from queue import Queue
import graphviz as gv
import numpy as np
from sklearn import datasets
from sklearn.cross_validation import train_test_split
class DecisionTree:
# Decision tree
tree = {}
import sys, re
from pathlib import Path
def preprocessor(text):
# Remove comments
text = re.sub(r'\/\/.+', '', text)
text = re.sub(r'\/\*(\*(?!\/)|[^*])*\*\/', '', text)
# Remove the package name
text = re.sub(r'package\s\w+(\.\w+)+;', '', text)
import requests, json, sys
from bs4 import BeautifulSoup
FILE = 'comments.txt'
PAGE = 50
TYPE = ''
def get_comments(appid):
with open(FILE, 'a') as file:
for page in range(1, 101):
count = 100;
dimen = 100;
test = 100;
function ret = distance(a, b)
ret = sqrt(sum((a.-b).^2,2));
end
function ret = find_k_nearest_naive(x, p, k)
[val, r] = sort(distance(x,p));
@zhenghaoz
zhenghaoz / parser.cpp
Created November 20, 2016 02:57
Experimental LL(1) Parser
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <map>
#include <climits>
#include <cctype>
#include <vector>
#include <set>
#include <algorithm>