Skip to content

Instantly share code, notes, and snippets.

View stormxuwz's full-sized avatar
🤣
Sleepy?

Wenzhao Xu stormxuwz

🤣
Sleepy?
View GitHub Profile
@stormxuwz
stormxuwz / rf_python.py
Created July 18, 2017 00:00
random forest in python
# gist only to keep record from https://www.jiqizhixin.com/articles/bb59b879-e030-400d-abbc-d9c0708266ff
# Random Forest Algorithm on Sonar Dataset
from random import seed
from random import randrange
from csv import reader
from math import sqrt
# Load a CSV file
def load_csv(filename):
@stormxuwz
stormxuwz / coverIntervals.py
Last active May 22, 2017 22:20
coverIntervals.py
# list_forecasts = [[1,3],[2,5]]
## cover(1pm, 7pm, [[1,3], [5,7]])
## return [[3,5]]
def cover(startTime, endTime, list_forecasts):
n = len(list_forecasts)
@stormxuwz
stormxuwz / plot_gly_on_map.R
Created April 28, 2017 23:49
customized glyph-maps
plot_gly_on_map <- function(newDF, global = FALSE, trend = FALSE, outputFile = "test.png"){
# newDF$value <- newDF$summerSum_UHY - newDF$springSum_UHY
longRange <- range(newDF$Long)
latRange <- range(newDF$Lat)
bbox <- make_bbox(longRange,latRange,f = 0.3)
# myMap <- get_map(location=bbox, source="stamn",crop=TRUE,color="bw",maptype="terrain")
myMap <- get_map(location = bbox, maptype="toner-lite", source="stamen",zoom=7,color = "bw",crop=TRUE)
# ggmap(myMap)
SU_locations <- unique(newDF[,c("Station","Lat","Long")])
-- LaunchBar Action Script
-- apple script to append launchbar input to the last line of omnioutliner
on handle_string(_string)
tell application "OmniOutliner 4.6.1"
set theDocument to the front document
set newRow to make new row at last row of front document
set topic of newRow to _string
outdent newRow
# This is a pure python K-means implementation
import numpy as np
def calDistance(x,y):
# return the distance of x and y
return np.sum((x-y)**2)
def assignClusters(centers,data):
distance = np.zeros((len(data),len(centers)))
@stormxuwz
stormxuwz / classfication_method.R
Created September 22, 2016 03:12
Music information retrieve for music classification
## Classification starts now
library(MASS)
library(e1071)
library(rda)
####################################
qda.model=function(traindata){
qda.result=qda(Y~.,data=traindata)
return(qda.result)
}
randomForest_clf <- function(matTrain,trainLabel,matTest,...){
library(randomForest)
rf_model<-randomForest(matTrain,trainLabel,ntree=500)
rf_predict<-predict(rf_model,matTest)
return(rf_predict)
}
xgboost_clf_1000 <- function(matTrain,trainLabel,matTest,...){
library(xgboost)
from __future__ import division
import numpy as np
import chainer # only for import the data at this script
def softmax(z):
# z is a vector
return np.exp(z) / np.sum(np.exp(z))
def sigmoid(x):
@stormxuwz
stormxuwz / ts_seg.py
Created February 25, 2016 21:09
time series segmentation
import numpy as np
def slidingWindow(x,max_error):
n=len(x)
leftNode=0
segmentList=[]
print n
while leftNode<n-1:
print leftNode
@stormxuwz
stormxuwz / onlineClf.py
Created November 18, 2015 01:05
some online algorithm
from __future__ import division
import numpy as np
class OnlineClf(object):
def __init__(self,iterNum,R):
self.w=None
self.iterNum=iterNum
self.misNum=[[0,0]]