This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function cancellablePromise(executor) { | |
var deferred = Promise.defer(); | |
var cancelled = false; | |
var promise = new Promise(executor).then(function(result) { | |
if (!cancelled) deferred.resolve(); | |
else return arguments[0] | |
}); | |
var actualPromise = Promise.all(deferred.promise, promise) | |
.then(function(result) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"presets": ["es2015", "stage-0"] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
irisCluster = kmeans(iris[,1:3], nlevels(iris$Species), nstart=20) | |
iris$cluster = irisCluster$cluster | |
# build contingency table | |
t = table(iris$Species, iris$cluster) | |
ggplot(data=iris) + geom_point(aes(Sepal.Length, Sepal.Width, color=Species)) + | |
geom_point(aes(Sepal.Length, Sepal.Width), data=as.data.frame(irisCluster$centers), size=5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pricing prediction with kmeans | |
# hypothesis: lotsize, bedrooms, bathrms, stories affects price | |
# we use kmeans to cluster into N clusters and use mean price | |
# of that's cluster as a prediction method | |
library(ggplot2) | |
library(plyr) | |
library(arimo) | |
ddf = arimo.getDDF('housing') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pricing prediction with linear regression | |
# we use linear regressions to predict the price of house | |
# then use RMSE to evaluate the model | |
library(arimo) | |
housing_ddf = arimo.getDDF('housing') | |
housing = head(ddf, nrow(ddf)) | |
splitdf <- function(dataframe, ratio=0.8, seed=NULL) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Visualize iris data using T-SNE | |
library(ggplot2) | |
library(tsne) | |
r = tsne(iris[, 2:4]) | |
r2 = as.data.frame(r) | |
names(r2) = c('x', 'y') | |
r2 = cbind(r2, class=iris$Species) | |
ggplot(r2) + geom_point(aes(x, y, color=class)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An example of using decision tree to classify iris data | |
library("party") | |
splitdf <- function(dataframe, ratio=0.8, seed=NULL) { | |
if (!is.null(seed)) set.seed(seed) | |
index <- 1:nrow(dataframe) | |
trainindex = sample(1:nrow(dataframe), size=ratio*nrow(dataframe)) | |
trainset <- dataframe[trainindex, ] | |
testset <- dataframe[-trainindex, ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("nnet") | |
splitdf <- function(dataframe, ratio=0.8, seed=NULL) { | |
if (!is.null(seed)) set.seed(seed) | |
index <- 1:nrow(dataframe) | |
trainindex = sample(1:nrow(dataframe), size=ratio*nrow(dataframe)) | |
trainset <- dataframe[trainindex, ] | |
testset <- dataframe[-trainindex, ] | |
list(train=trainset,test=testset) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FCC's Census Block Conversions API | |
# http://www.fcc.gov/developers/census-block-conversions-api | |
latlong2fips <- function(latitude, longitude) { | |
url <- "http://data.fcc.gov/api/block/find?format=json&latitude=%f&longitude=%f" | |
url <- sprintf(url, latitude, longitude) | |
json <- RCurl::getURL(url) | |
json <- RJSONIO::fromJSON(json) | |
as.character(json$County['FIPS']) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo docker rmi `sudo docker images --format "{{.ID}},{{.Tag}}" | grep "<none>" | awk -F',' '{print $1}'` |