Skip to content

Instantly share code, notes, and snippets.

View hoxo-m's full-sized avatar
🌅
旅人算

hoxo_m hoxo-m

🌅
旅人算
View GitHub Profile
@hoxo-m
hoxo-m / svm_animation.R
Created September 13, 2019 13:03
機械学習やってるGIFつくるやつ
library(dplyr)
library(ggplot2)
data <- iris %>% filter(Species != "setosa") %>%
select(Petal.Width, Sepal.Length, Species) %>%
sample_frac(1)
ggplot(data, aes(Petal.Width, Sepal.Length)) +
geom_point(aes(color = Species), size=4) + xlab("") + ylab("") +
scale_x_continuous(label=NULL) +
@hoxo-m
hoxo-m / qiita_get_organization_member.R
Created November 17, 2019 14:32
Qiita の Organization のメンバーIDを取得する関数
library(tidyverse)
library(rvest)
qiita_get_organization_member <- function(organization) {
target_url <- str_glue("https://qiita.com/organizations/{organization}/members")
sess <- html_session(target_url)
member_ids <- c()
while (!is.null(sess)) {
ids <- sess %>%
@hoxo-m
hoxo-m / app.R
Created December 5, 2019 22:44
Sparkline in DT
library(shiny)
library(DT)
library(sparkline)
library(tidyverse)
ui <- fluidPage(
titlePanel("Sparkline in DT"),
sidebarLayout(NULL,
mainPanel(
dataTableOutput("table_with_sparkline")
@hoxo-m
hoxo-m / head.mcmc.R
Created December 18, 2019 09:31
head.mcmc
head.mcmc <- function(x, n = 6L, ...) {
mcpar <- attr(x, "mcpar")
start <- mcpar[1]
max_end <- mcpar[2]
thin <- mcpar[3]
niter <- nrow(x)
end <- start + niter - 1
attr(x, "mcpar")[2:3] <- c(end, 1)
out <- window(x, end = min(start + n - 1, end))
@hoxo-m
hoxo-m / furrr_test.R
Last active May 8, 2020 09:58
furrr test
library(purrr)
library(furrr)
plan(multiprocess)
x <- iris$Sepal.Length
n_cores <- parallel::detectCores() - 1
N <- length(x)
k <- ceiling(N / n_cores)
split_factor <- gl(n_cores, k) %>% head(N)
x_list <- split(x, split_factor)
@hoxo-m
hoxo-m / iter_index_matrix.R
Last active August 26, 2020 05:35
iterator for index matrix
iter_index_matrix <- function(dims, chunk_size = 1L) {
f_split <- cumprod(dims) <= chunk_size
has_next <- TRUE
if (all(f_split)) {
next_element <- function() {
if (!has_next) stop("StopIteration")
has_next <<- FALSE
expand.grid(lapply(dims, seq_len))
}
} else {