diff --git a/.gitignore b/.gitignore index 6d11f9400b..4d56e42f75 100644 --- a/.gitignore +++ b/.gitignore @@ -78,4 +78,6 @@ examples/models/mean_classifier/build/ notebooks/my-ml-deployment/ wrappers/s2i/python/Dockerfile -wrappers/s2i/python/_wrappers \ No newline at end of file +wrappers/s2i/python/_wrappers + +.Rhistory diff --git a/examples/models/r_mnist/.Rhistory b/examples/models/r_mnist/.Rhistory deleted file mode 100644 index f05ad50259..0000000000 --- a/examples/models/r_mnist/.Rhistory +++ /dev/null @@ -1,174 +0,0 @@ -library(caret) -install.packages("caret") -install.packages("doParallel") -install.packages("e1071") -library(caret) -library(doParallel) -# Enable parallel processing. -cl <- makeCluster(detectCores()) -registerDoParallel(cl) -# Load the MNIST digit recognition dataset into R -# http://yann.lecun.com/exdb/mnist/ -# assume you have all 4 files and gunzip'd them -# creates train$n, train$x, train$y and test$n, test$x, test$y -# e.g. train$x is a 60000 x 784 matrix, each row is one digit (28x28) -# call: show_digit(train$x[5,]) to see a digit. -# brendan o'connor - gist.github.com/39760 - anyall.org -load_mnist <- function() { -load_image_file <- function(filename) { -ret = list() -f = file(filename,'rb') -readBin(f,'integer',n=1,size=4,endian='big') -ret$n = readBin(f,'integer',n=1,size=4,endian='big') -nrow = readBin(f,'integer',n=1,size=4,endian='big') -ncol = readBin(f,'integer',n=1,size=4,endian='big') -x = readBin(f,'integer',n=ret$n*nrow*ncol,size=1,signed=F) -ret$x = matrix(x, ncol=nrow*ncol, byrow=T) -close(f) -ret -} -load_label_file <- function(filename) { -f = file(filename,'rb') -readBin(f,'integer',n=1,size=4,endian='big') -n = readBin(f,'integer',n=1,size=4,endian='big') -y = readBin(f,'integer',n=n,size=1,signed=F) -close(f) -y -} -train <<- load_image_file('train-images-idx3-ubyte') -test <<- load_image_file('t10k-images-idx3-ubyte') -train$y <<- load_label_file('train-labels-idx1-ubyte') -test$y <<- load_label_file('t10k-labels-idx1-ubyte') -} -show_digit <- function(arr784, col=gray(12:1/12), ...) { -image(matrix(arr784, nrow=28)[,28:1], col=col, ...) -} -train <- data.frame() -test <- data.frame() -# Load data. -load_mnist() -# Normalize: X = (X - min) / (max - min) => X = (X - 0) / (255 - 0) => X = X / 255. -train$x <- train$x / 255 -# Setup training data with digit and pixel values with 60/40 split for train/cv. -inTrain = data.frame(y=train$y, train$x) -inTrain$y <- as.factor(inTrain$y) -trainIndex = createDataPartition(inTrain$y, p = 0.60,list=FALSE) -training = inTrain[trainIndex,] -cv = inTrain[-trainIndex,] -# SVM. 95/94. -fit <- train(y ~ ., data = head(training, 1000), method = 'svmRadial', tuneGrid = data.frame(sigma=0.0107249, C=1)) -results <- predict(fit, newdata = head(cv, 1000)) -confusionMatrix(results, head(cv$y, 1000)) -saveRDS(fit, file = "model.Rds", compress = TRUE) -View(fit) -View(training) -results <- predict(fit, newdata = head(cv, 1000)) -results -confusionMatrix(results, head(cv$y, 1000)) -results <- predict(fit, newdata = head(cv, 1000), type='response') -results <- predict(fit, newdata = head(cv, 1000), type='prob') -results -# SVM. 95/94. -fit <- train(y ~ ., data = head(training, 1000), method = 'naiveBayes', tuneGrid = data.frame(sigma=0.0107249, C=1)) -# SVM. 95/94. -fit <- train(y ~ ., data = head(training, 1000), method = 'xgbTree', tuneGrid = data.frame(sigma=0.0107249, C=1)) -# SVM. 95/94. -fit <- train(y ~ ., data = head(training, 1000), method = 'randomGLM', tuneGrid = data.frame(sigma=0.0107249, C=1)) -# SVM. 95/94. -#fit <- train(y ~ ., data = head(training, 1000), method = 'svmRadial', tuneGrid = data.frame(sigma=0.0107249, C=1)) -fit <- train(y ~ ., data = head(training, 1000), method = 'randomGLM') -# SVM. 95/94. -#fit <- train(y ~ ., data = head(training, 1000), method = 'svmRadial', tuneGrid = data.frame(sigma=0.0107249, C=1)) -fit <- train(y ~ ., data = head(training, 1000), method = 'bayesGLM') -library(caret) -library(doParallel) -# Enable parallel processing. -cl <- makeCluster(detectCores()) -registerDoParallel(cl) -# Load the MNIST digit recognition dataset into R -# http://yann.lecun.com/exdb/mnist/ -# assume you have all 4 files and gunzip'd them -# creates train$n, train$x, train$y and test$n, test$x, test$y -# e.g. train$x is a 60000 x 784 matrix, each row is one digit (28x28) -# call: show_digit(train$x[5,]) to see a digit. -# brendan o'connor - gist.github.com/39760 - anyall.org -load_mnist <- function() { -load_image_file <- function(filename) { -ret = list() -f = file(filename,'rb') -readBin(f,'integer',n=1,size=4,endian='big') -ret$n = readBin(f,'integer',n=1,size=4,endian='big') -nrow = readBin(f,'integer',n=1,size=4,endian='big') -ncol = readBin(f,'integer',n=1,size=4,endian='big') -x = readBin(f,'integer',n=ret$n*nrow*ncol,size=1,signed=F) -ret$x = matrix(x, ncol=nrow*ncol, byrow=T) -close(f) -ret -} -load_label_file <- function(filename) { -f = file(filename,'rb') -readBin(f,'integer',n=1,size=4,endian='big') -n = readBin(f,'integer',n=1,size=4,endian='big') -y = readBin(f,'integer',n=n,size=1,signed=F) -close(f) -y -} -train <<- load_image_file('train-images-idx3-ubyte') -test <<- load_image_file('t10k-images-idx3-ubyte') -train$y <<- load_label_file('train-labels-idx1-ubyte') -test$y <<- load_label_file('t10k-labels-idx1-ubyte') -} -show_digit <- function(arr784, col=gray(12:1/12), ...) { -image(matrix(arr784, nrow=28)[,28:1], col=col, ...) -} -train <- data.frame() -test <- data.frame() -# Load data. -load_mnist() -# Normalize: X = (X - min) / (max - min) => X = (X - 0) / (255 - 0) => X = X / 255. -train$x <- train$x / 255 -# Setup training data with digit and pixel values with 60/40 split for train/cv. -inTrain = data.frame(y=train$y, train$x) -inTrain$y <- as.factor(inTrain$y) -trainIndex = createDataPartition(inTrain$y, p = 0.60,list=FALSE) -training = inTrain[trainIndex,] -cv = inTrain[-trainIndex,] -# SVM. 95/94. -#fit <- train(y ~ ., data = head(training, 1000), method = 'svmRadial', tuneGrid = data.frame(sigma=0.0107249, C=1)) -fit <- train(y ~ ., data = head(training, 1000), method = 'bayesGLM') -results <- predict(fit, newdata = head(cv, 1000), type='prob') -confusionMatrix(results, head(cv$y, 1000)) -saveRDS(fit, file = "model.Rds", compress = TRUE) -# SVM. 95/94. -#fit <- train(y ~ ., data = head(training, 1000), method = 'svmRadial', tuneGrid = data.frame(sigma=0.0107249, C=1)) -fit <- train(y ~ ., data = head(training, 1000), method = 'bayesGLM') -# SVM. 95/94. -#fit <- train(y ~ ., data = head(training, 1000), method = 'svmRadial', tuneGrid = data.frame(sigma=0.0107249, C=1)) -fit <- train(y ~ ., data = head(training, 1000), method = 'rpart2') -results <- predict(fit, newdata = head(cv, 1000), type='prob') -View(results) -install.packages("klaR") -install.packages("gbm") -install.packages("pls") -d = data.frame(c(1,2,3)) -View(d) -View(d) -View(d) -delete d -d <- data.frame((1,2,3)) -d <- data.frame(1,2,3) -ids <- 1:3 -cn <- Character(length(d)) -cn <- Character(length=length(ids)) -cat("X",1) -"X"+1 -"X".1 -paste("x",1) -paste("x",1,collapse = TRUE) -paste("x",1,collapse = True) -paste("x",1,sep="") -for (i in seq_along(idx)){idx[i] <- paste("X",idx[i],sep = "")} -for (i in seq_along(ids)){ids[i] <- paste("X",ids[i],sep = "")} -colnames(d) <- ids -for (i in seq_along(ids)){ids[i] <- paste("T",ids[i],sep = "")} -colnames(d) <- ids