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(ggplot2) | |
set.seed(1001) | |
start <- 2 | |
end <- 20 | |
N <- 100 | |
x <- runif(N, start, end) |
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(dplyr) | |
# If we don't have 'TOYOTA PRADO' in the set? | |
test <- c('ROVER', 'CRUISER', 'TOYOTA', 'TOYOTA PRADO', 'NISSAN') | |
old <- c('ROVER', 'CRUISER', 'TOYOTA') | |
new <- c('LandRover', 'LandRover', 'Toyota') |
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
#'--- | |
#'output: | |
#' pdf_document: | |
#' number_sections: true | |
#' toc: true | |
#' toc_depth: 2 | |
#'title: "RandomForest with distance to points" | |
#'author: Tim Lucas | |
#'fontsize: 8pt |
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
# pca | |
d <- data.frame(x = runif(100)) | |
d$y <- d$x + runif(100, -0.01, 0.01) | |
plot(y ~ x, data = d) |
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
# devtools::install_github("thomasp85/patchwork") | |
library(patchwork) | |
library(paletteer) | |
library(ggplot2) | |
ggplot(mtcars, aes(mpg, disp, colour = factor(cyl))) + | |
geom_point() + | |
scale_colour_paletteer_d('palettetown', 'spearow') + | |
ggtitle('Spearow loves mtcars') + |
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(forcats) | |
library(ggplot2) | |
ggplot(mtcars, aes(x = disp, y = mpg)) + | |
geom_point() + | |
facet_wrap(~ factor(gear)) | |
ggplot(mtcars, aes(x = disp, y = mpg)) + | |
geom_point() + |
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
head(mtcars) | |
a <- 0.1 | |
ggplot(mtcars, aes(mpg, disp)) + | |
geom_smooth(method = 'lm', level = 0.99, alpha = a) + | |
geom_smooth(method = 'lm', level = 0.97, alpha = a) + | |
geom_smooth(method = 'lm', level = 0.94, alpha = a) + | |
geom_smooth(method = 'lm', level = 0.92, alpha = a) + |
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
#'--- | |
#'output: | |
#' pdf_document: | |
#' number_sections: true | |
#' toc: true | |
#' toc_depth: 2 | |
#' keep_tex: true | |
#'title: "test" | |
#'author: Tim Lucas |
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
get_preds <- function(t){ | |
stopifnot(inherits(t, 'train')) | |
oos <- t$pred %>% arrange(rowIndex) | |
row_matches <- sapply(1:length(t$bestTune), function(x) oos[, names(t$bestTune)[x]] == t$bestTune[[x]]) | |
best_rows <- rowMeans(row_matches) == 1 | |
d <- oos[best_rows, ] | |
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
set.seed(17022020) | |
# "inside" people and countries | |
names_in <- c('lisa', 'suzanne', 'rohan') | |
countries_in <- c('germany', 'austria-hungary', 'italy', 'france') | |
# "outside" | |
names_out <- c('tim', 'jen') |