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
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - | |
cat <<EOF > /etc/apt/sources.list.d/kubernetes.list | |
deb http://apt.kubernetes.io/ kubernetes-xenial main | |
EOF | |
apt-get update | |
apt-get install -y docker.io | |
apt-get install -y kubelet kubeadm kubectl kubernetes-cni |
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
#!/bin/bash | |
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv E56151BF | |
DISTRO=$(lsb_release -is | tr '[:upper:]' '[:lower:]') | |
CODENAME=$(lsb_release -cs) | |
echo "deb http://repos.mesosphere.io/${DISTRO} ${CODENAME} main" | \ | |
sudo tee /etc/apt/sources.list.d/mesosphere.list | |
sudo apt-get update | |
sudo apt-get install -y mesos |
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}'` |
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
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
# 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
# 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
# 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
# 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
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) |