Skip to content

Instantly share code, notes, and snippets.

KUROYANAGI KEIICHI Keiku

Block or report user

Report or block Keiku

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Keiku
Keiku / dplyr_se.r
Created Mar 10, 2017
Summarising by standard evaluation with dplyr.
View dplyr_se.r
library(dplyr)
library(lazyeval)
df <- data_frame(group = c(1, 2, 2, 3, 3, 3))
g <- "group"
df %>%
group_by_(g) %>%
summarise_(
@Keiku
Keiku / impute.py
Created Mar 10, 2017
Impute some missing columns with pandas.
View impute.py
import pandas as pd
df = pd.DataFrame({'A':['A1', 'A2', 'A3'], 'B':[None, 'B2', None]})
df
# Out[51]:
# A B
# 0 A1 None
# 1 A2 B2
# 2 A3 None
@Keiku
Keiku / pandas_sample.py
Last active Mar 1, 2017
The example codes on pandas library.
View pandas_sample.py
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}, index=['a', 'b', 'c'])
# Out[75]:
# A B
# a 1 4
# b 2 5
# c 3 6
for col in df:
print(col)
# A
@Keiku
Keiku / roc_auc.py
Last active Oct 24, 2018
Plot ROC curve.
View roc_auc.py
import matplotlib.pyplot as plt
from sklearn.metrics import roc_curve, auc
import seaborn as sns
sns.set('talk', 'whitegrid', 'dark', font_scale=1.5, font='Ricty',
rc={"lines.linewidth": 2, 'grid.linestyle': '--'})
fpr, tpr, _ = roc_curve([1, 0, 1, 0, 1, 0, 0], [0.9, 0.8, 0.7, 0.7, 0.6, 0.5, 0.4])
roc_auc = auc(fpr, tpr)
@Keiku
Keiku / dplyr_examples.r
Created Feb 23, 2017
The example codes on dplyr package.
View dplyr_examples.r
library(dplyr)
iris_df <- as_data_frame(iris)
iris_df %>% rename_(.dots = setNames(names(.), toupper(names(.)))) %>% head(2)
# A tibble: 2 × 5
# SEPAL.LENGTH SEPAL.WIDTH PETAL.LENGTH PETAL.WIDTH SPECIES
# <dbl> <dbl> <dbl> <dbl> <fctr>
# 1 5.1 3.5 1.4 0.2 setosa
# 2 4.9 3.0 1.4 0.2 setosa
@Keiku
Keiku / extract_subset.r
Last active Feb 20, 2017
Extract a set from the multiple vectors.
View extract_subset.r
a <- c(1, 3, 5, 7, 9)
b <- c(3, 6, 8, 9, 10)
c <- c(2, 3, 4, 5, 7, 9)
intersect_all <- function(...) Reduce(intersect, list(...))
union_all <- function(...) Reduce(union, list(...))
intersect_all(a, b, c)
# [1] 3 9
union_all(a, b, c)
@Keiku
Keiku / tqdm.py
Created Feb 17, 2017
Print progress bar.
View tqdm.py
import time
from tqdm import tqdm
pbar = tqdm(["1", "2", "3", "4", "5"])
for char in pbar:
pbar.set_description("Processing %s" % char)
time.sleep(1)
# 0%| | 0/5 [00:00<?, ?it/s]
# Processing 1: 20%|██████▏ | 1/5 [00:01<00:04, 1.00s/it]
# Processing 2: 40%|████████████▍ | 2/5 [00:02<00:03, 1.00s/it]
@Keiku
Keiku / check_id_sets.r
Created Feb 16, 2017
Check duplicate id list of some tables.
View check_id_sets.r
library(gplots)
library(dplyr)
library(magrittr)
check_id_sets <- function(ids){
ids_venn <- gplots::venn(ids, show.plot=FALSE)
ids_list <- unlist(as.list(ids_venn))
mat_dim <- c((length(ids_list) / (length(ids)+1)), length(ids)+1)
id_sets <- ids_list %>%
matrix(., mat_dim) %>%
@Keiku
Keiku / command.sh
Last active Jun 23, 2017
A list of linux commands.
View command.sh
# compress/decompress zip file.
zip file.csv.zip file.csv
unzip file.csv.zip
# compress/decompress gz file.
gzip file.csv
gzip -d file.csv.gz
# compress/decompress bz2 file.
bzip2 file.csv
@Keiku
Keiku / chisq.test_by_group.r
Created Feb 10, 2017
Chi-square testing in each group.
View chisq.test_by_group.r
library(dplyr)
library(purrr)
library(broom)
df <- data_frame(
group = rep(letters[1:2], each = 50),
cat1 = letters[round(runif(100) * 5) + 1],
cat2 = letters[round(runif(100) * 3) + 1]
)
You can’t perform that action at this time.