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
# Takes approx. 15min | |
trainData <- extract_feature("train/", width, height) | |
# Takes slightly less | |
testData <- extract_feature("test1/", width, height, labelsExist = F) |
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
# Check processing on second cat | |
par(mar = rep(0, 4)) | |
testCat <- t(matrix(as.numeric(trainData$X[2,]), | |
nrow = width, ncol = height, T)) | |
image(t(apply(testCat, 2, rev)), col = gray.colors(12), | |
axes = F) | |
# Save / load | |
save(trainData, testData, file = "catdogData.RData") | |
# load("catdogData.RData") |
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
# Fix structure for 2d CNN | |
train_array <- t(trainData$X) | |
dim(train_array) <- c(50, 50, nrow(trainData$X), 1) | |
# Reorder dimensions | |
train_array <- aperm(train_array, c(3,1,2,4)) | |
test_array <- t(testData) | |
dim(test_array) <- c(50, 50, nrow(testData), 1) | |
# Reorder dimensions | |
test_array <- aperm(test_array, c(3,1,2,4)) |
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
# Compute probabilities and predictions on test set | |
predictions <- predict_classes(model, test_array) | |
probabilities <- predict_proba(model, test_array) | |
# Visual inspection of 32 cases | |
set.seed(100) | |
random <- sample(1:nrow(testData), 32) | |
preds <- predictions[random,] | |
probs <- as.vector(round(probabilities[random,], 2)) |
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
# Install (if necessary) and load nlme and lme4 | |
library(nlme) | |
library(lme4) | |
# Load dataset, inspect size and additional info | |
data(Arabidopsis) | |
dim(Arabidopsis) # 625 observations, 8 variables | |
?Arabidopsis | |
attach(Arabidopsis) |
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
# Overview of the variables | |
par(mfrow = c(2,4)) | |
barplot(table(reg), ylab = "Frequency", main = "Region") | |
barplot(table(popu), ylab = "Frequency", main = "Population") | |
barplot(table(gen), ylab = "Frequency", las = 2, main = "Genotype") | |
barplot(table(rack), ylab = "Frequency", main = "Rack") | |
barplot(table(nutrient), ylab = "Frequency", main = "Nutrient") | |
barplot(table(amd), ylab = "Frequency", main = "AMD") | |
barplot(table(status), ylab = "Frequency", main = "Status") | |
hist(total.fruits, col = "grey", main = "Total fruits", xlab = NULL) |
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
# Transform the three factor variables gen, rack and nutrient | |
Arabidopsis[,c("gen","rack","nutrient")] <- lapply(Arabidopsis[,c("gen","rack","nutrient")], factor) | |
str(Arabidopsis) | |
# Re-attach after correction, ignore warnings | |
attach(Arabidopsis) | |
# Add 1 to total fruits, otherwise log of 0 will prompt error | |
total.fruits <- log(1 + total.fruits) |
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
# gen x popu table | |
table(gen, popu) | |
# Any NAs? | |
any(is.na(Arabidopsis)) # FALSE |
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
LM <- lm(total.fruits ~ rack + nutrient + amd + status) | |
summary(LM) | |
par(mfrow = c(2,2)) | |
plot(LM) |
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
GLM <- gls(total.fruits ~ rack + nutrient + amd + status, | |
method = "ML") | |
summary(GLM) |