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(purrr) | |
| data_dir <- here::here() | |
| base_url <- "http://www.pjm.com" | |
| url <- sprintf("%s/pub/operations/hist-meter-load", base_url) | |
| years <- 1993L:2018L | |
| # check for robots.txt | |
| robotstxt::get_robotstxt(base_url) |
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
| #' description: | |
| #' Get the AUC for the {validation,test} data set for a given model. | |
| #' usage: | |
| #' list(best_dl, best_gbm) %>% map_dbl(h2o_auc_v) %>% set_names('DL AUC', 'GBM AUC') | |
| #' list(best_dl, best_gbm) %>% map_dbl(h2o_auc_t) %>% set_names('DL AUC', 'GBM AUC') | |
| library(h2o) | |
| library(purrr) | |
| h2o_auc_t <- compose(h2o.auc, partial(h2o.performance, newdata = test)) | |
| h2o_auc_v <- compose(h2o.auc, partial(h2o.performance, newdata = valid)) |
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
| Multiclass classifier | |
| ---- | |
| ```{r, include=FALSE} | |
| knitr::opts_chunk$set( | |
| comment = "#>", | |
| collapse = TRUE, | |
| cache = TRUE, | |
| echo = FALSE, | |
| out.width = "70%", |
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
| Spike and Slab Prior | |
| ---- | |
| ```{r, message=FALSE} | |
| library(magrittr) | |
| ``` | |
| ```{r} | |
| prior_plot <- function(lower, upper, sigma, ...) { | |
| seq(lower, upper, l=100) %>% plot(., dnorm(., 0, sigma)) | |
| abline(v= 0, lty = 2, col = "red") |
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
| compiler::enableJIT(0) | |
| compiler::enableJIT(0) | |
| rustinr::rust(code = ' | |
| // #[rustr_export] | |
| pub fn fib_rust(a : i32) -> RResult<f64>{ | |
| let mut first = 0.0; | |
| let mut second = 1.0; | |
| let mut third = 0.0; | |
| for _ in 0..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
| library(rvest) | |
| library(purrr) | |
| library(stringr) | |
| url <- "http://ellisp.github.io/blog/2016/11/06/forecastxgb" | |
| robotstxt::get_robotstxt(url) | |
| url %>% | |
| read_html() %>% html_nodes("span") %>% html_text() %>% | |
| reduce(., str_c) %>% |
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(purrr) | |
| # two regressions | |
| lm_fit <- lm(mpg ~ wt + cyl, data = mtcars) | |
| bayes_fit <- rstanarm::stan_glm(mpg ~ wt + cyl, data = mtcars) | |
| # design matrix [32 x 3] | |
| X <- model.matrix(lm_fit) | |
| # coefficient matrix [3 x 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
| library(gistr) | |
| # create | |
| gist_create(files='../create_gist.R', | |
| description='Create gist via R.') | |
| # update | |
| gists(what = "minepublic")[[1]] %>% | |
| update_files('../create_gist.R') %>% | |
| update() |
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(tidyverse) | |
| y <- as.matrix(mtcars$mpg) | |
| X <- model.matrix(mpg ~ ., mtcars) | |
| # linear regression | |
| solve(crossprod(X)) %*% t(X) %*% y | |
| solve(crossprod(X) + 0 * diag(rep(1, ncol(X)))) %*% t(X) %*% y | |
| # ridge regression |
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
| .First <- function() { | |
| # set TZ if unset | |
| if (is.na(Sys.getenv("TZ", unset = NA))) | |
| Sys.setenv(TZ = "America/New_York") | |
| # bail if revo R | |
| if (exists("Revo.version")) | |
| return() |
OlderNewer