This file contains hidden or 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
# Example of training a glm model on a spam data-set, using the caret library. | |
library(caret) | |
library(kernlab) | |
# Load spam dataset. | |
data(spam) | |
# Split the data into a training/test set by 60% training/40% test. | |
inTrain <- createDataPartition(y = spam$type, p=0.6, list=FALSE) | |
training <- spam[inTrain,] |
This file contains hidden or 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(AppliedPredictiveModeling) | |
library(caret) | |
data(AlzheimerDisease) | |
adData = data.frame(diagnosis,predictors) | |
trainIndex = createDataPartition(diagnosis, p = 0.60,list=FALSE) | |
training = adData[trainIndex,] | |
testing = adData[-trainIndex,] |
This file contains hidden or 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(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 |
This file contains hidden or 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(caret) | |
library(doParallel) | |
library(reshape2) | |
library(ggplot2) | |
# Enable parallel processing. | |
cl <- makeCluster(detectCores()) | |
registerDoParallel(cl) | |
# Load the MNIST digit recognition dataset into R |
This file contains hidden or 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(caret) | |
data(faithful) | |
set.seed(333) | |
# Plot data. | |
plot(x=faithful$waiting, faithful$eruptions) | |
# Calculate linear model. |
This file contains hidden or 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
# Question 1 | |
library(AppliedPredictiveModeling) | |
library(caret) | |
data(segmentationOriginal) | |
set.seed(125) | |
#inTrain <- createDataPartition(segmentationOriginal$Case, list=FALSE) | |
inTrain <- data$Case == "Train" |
This file contains hidden or 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
# Quiz 4 | |
# Question 1. | |
library(ElemStatLearn) | |
library(randomForest) | |
library(caret) | |
data(vowel.train) | |
data(vowel.test) |

This file contains hidden or 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
# Simple implementation of Selection Sort and Quicksort in R. | |
# Quick sort algorithm: | |
# 1. Select a random value from the array. | |
# 2. Put all values less than the random in arrayLeft. | |
# 3. Put all values greater than the random in arrayRight. | |
# 4. If arrayLeft or arrayRight has more than 1 value, repeat the above steps on it. | |
# 5. The sorted result is arrayLeft, random, arrayRight. | |
# | |
# Selection sort algorithm: | |
# 1. Find the smallest value in the array and move it to a result array. |
This file contains hidden or 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
is.prime <- function(num) { | |
if (num == 2) { | |
TRUE | |
} else if (any(num %% 2:(num-1) == 0)) { | |
FALSE | |
} else { | |
TRUE | |
} | |
} |