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
| find_ratio <- function(.df, ...) { | |
| group_var <- enquos(...) | |
| result <- | |
| .df %>% | |
| group_by(!!!group_var) %>% | |
| summarise(n = n(), avg_n = n / nrow(.)) | |
| return(result) | |
| } |
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
| class Timer: | |
| def __init__(self): | |
| self.start = time.time() | |
| def restart(self): | |
| self.start = time.time() | |
| def get_time_hhmmss(self): | |
| end = time.time() | |
| m, s = divmod(end - self.start, 60) |
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
| import random | |
| import time | |
| import numpy as np | |
| import pandas as pd | |
| import torch | |
| import torch.nn as nn | |
| import torch.nn.functional as 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
| df_periodicity <- filter(df, id %in% sample(unique), month == 12, day == 29) | |
| df_event <- | |
| df %>% | |
| filter(month == 12, day == 29) %>% | |
| semi_join(df_periodicity, by = "id") %>% | |
| mutate( | |
| var1 = if_else(var1 == 0, NA, var1) # Except Events that do not occur | |
| var2 = if_else(var2 == 0, NA, var2) | |
| ) |
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
| plot_na <- function(df, start_date, end_date) { | |
| start_date <- paste(start_date, "00:00:00") | |
| end_date <- paste(end_date, "00:00:00") | |
| g <- | |
| df %>% | |
| filter(id %in% sample(unique(id), 20)) %>% | |
| ggplot(aes(dt, 0)) + | |
| geom_point() + | |
| sacle_x_datetime(limits = ymd_hms(c(start_date, end_date))) + |