Skip to content

Instantly share code, notes, and snippets.

View WooheonHong's full-sized avatar

WooHeon WooheonHong

  • Postech
  • Pohang, Korea
View GitHub Profile
@WooheonHong
WooheonHong / filter_small_category.r
Last active September 3, 2021 05:13
filter out small count category
find_ratio <- function(.df, ...) {
group_var <- enquos(...)
result <-
.df %>%
group_by(!!!group_var) %>%
summarise(n = n(), avg_n = n / nrow(.))
return(result)
}
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)
@WooheonHong
WooheonHong / pytorch_start.py
Last active October 24, 2021 04:45
Reproducible Pytorch
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
@WooheonHong
WooheonHong / timeseries_event_plot.r
Created May 29, 2021 13:31
Comparison having Periodicity Variables with Event Variables
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)
)
@WooheonHong
WooheonHong / timeseries_missing_plot.r
Created May 29, 2021 13:30
Check Time Series Missing Values by Devices
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))) +