This file contains 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
https://github.com/pytorch/pytorch/issues/958#issuecomment-309752126 |
This file contains 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
# -*- coding:utf8 -*- | |
# !/usr/bin/env python | |
from flask import Flask, request, session, make_response | |
from flask_pymongo import PyMongo | |
from utils.server import * | |
from utils.data import * | |
import pandas as pd | |
import numpy as np |
This file contains 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
# when you need to use tidyselect in a mutate function | |
# https://stackoverflow.com/questions/48353331/row-wise-operations-select-helpers-and-the-mutate-function-in-dplyr | |
tbl %>% mutate(a = select(., contains("abc"))) | |
# based on https://rpubs.com/wch/200398 | |
mtcars %>% purrrlyr::by_row(~any(is.na(.)), .collate = "rows", .to = "has_missing") | |
tibble(a=c(1, NA, 3), b=c(NA, 2, NA), c=c(NA, 5, 6)) %>% | |
mutate(pmap_int(., function(...) sum(lift_ld(is.na)(...)))) |
This file contains 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
xx <- "b" | |
data.frame(a=1:3, b=c(2, NA, 5)) %>% filter(!is.na(get(xx))) | |
data.frame(a=1:3, b=c(2, NA, 5)) %>% filter(!is.na(!!as.name(xx))) |
This file contains 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
x <- data.frame(a=1, b=2) | |
x %>% rename_at(vars(names(.)), ~letters[3:4]) | |
x %>% rename_all(~letters[3:4]) | |
x %>% rename_all(funs(str_c('prefix_', .))) | |
x %>% rename_at(vars(-starts_with("a")), ~str_c(., "_b")) # approx. |
This file contains 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
# https://www.enchufa2.es/archives/programming-with-dplyr-by-using-dplyr.html | |
# 1. reminder | |
starwars_mean <- function(var) { | |
var <- enquo(var) | |
starwars %>% group_by(!!var) | |
} | |
starwars_mean(homeworld) | |
# 2. parsing a string inside |
This file contains 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
``` r | |
library(dplyr) | |
x <- tibble(a=c(1, 2, 2, 3)) | |
x %>% group_by(a) %>% summarise(n()) | |
#> # A tibble: 3 x 2 | |
#> a `n()` | |
#> <dbl> <int> | |
#> 1 1 1 |
This file contains 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
pacman::p_load(tidyverse, xgboost) | |
# in xgboost: "cb" for "callback", "bst" for "booster" | |
cb_best_model <- function(print_improvements, save_cv_models) { | |
# callback is the main function that will be executed on every iteration | |
callback <- function(env = parent.frame(), finalize = FALSE) { | |
if (is.null(env$basket) || is.null(env$bst_folds)) | |
stop("'cb_best_model' callback requires 'basket' and 'bst_folds' lists | |
in its calling frame") |
This file contains 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) | |
# case 1 | |
forest %>% map(predictions) %>% map(assess) %>% transpose() %>% | |
map(~imap(., ~rename(.x, !!.y := value))) | |
# > ... works | |
forest %>% map(predictions) %>% map(assess) %>% transpose() %>% | |
map(~imap(~rename(.x, !!.y := value))) | |
# > Error in as_mapper(.f, ...) : argument ".f" is missing, with no default |
This file contains 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
``` | |
... package ‘parsnip’ successfully unpacked and MD5 sums checked | |
The downloaded binary packages are in | |
C:\Users\Gray\AppData\Local\Temp\Rtmps7lBHE\downloaded_packages | |
parsnip installed | |
Failed to install/load: | |
parsnip | |
``` |