Skip to content

Instantly share code, notes, and snippets.

import numpy as np
import pandas as pd
np.random.seed(1234)
start_date = "2017-07-01"
end_date = "2017-07-02"
_date_range = pd.date_range(start_date, end_date, freq="H")
_size = _date_range.shape[0]
@yuu-ito
yuu-ito / pandas_DataFrame_to_dict.ipynb
Last active December 7, 2016 01:29
Python pandas.DataFrame.to_dict
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yuu-ito
yuu-ito / dynamic_typing.py
Last active December 6, 2016 11:33
pythonでメタプログラミング
# https://docs.python.org/3.5/library/types.html
from types import MethodType
class Base(object):
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
def add_instance_method(self, method):
setattr(self, method.__name__, MethodType(method, self))
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
[y-ito@workspace ~]$ cat test.py
class Order():
    def __init__(self, name, campaigns=[]):
        self.name = name
        self.campaigns = campaigns

    def add(self,c):
@yuu-ito
yuu-ito / Dockerfile
Created August 10, 2016 04:55
[WIP]golangの開発環境Dockerfile
from centos:6
RUN yum install -y vim git wget tar
# useradd
RUN useradd -m y-ito \
&& echo "y-ito ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& echo 'y-ito:y-ito' | chpasswd
# Golang (1.6.3)
USER root
puts "start!"
bar ="->"
(1..5).each {
print "\r#{bar}"
sleep 0.5
bar = "-"+bar
}
puts "\nend!"
@yuu-ito
yuu-ito / titanicデータでの条件付き確率と事前確率の算出.R
Created June 10, 2015 01:41
ベイズ分類のための変量の特徴を見る。
library("magrittr")
library("dplyr")
data(Titanic)
t <- Titanic %>% as.data.frame %>% arrange(Survived,Class,Sex,Age)
t %>%
group_by(Survived) %>%
summarize(ClassCount=sum(Freq)) %>%
group_by %>%
# rcpp sandbox
gibbs_r <- function(n,thin){
# R実装のギブスサンプラー
mat <- matrix(0,nrow=n,ncol=2)
x <- 0
y <- 0
for(i in 1:n){
for(j in 1:thin){
x <- rgamma(1, 3, 1/(y*y+4) )
@yuu-ito
yuu-ito / midori_study_8.r
Last active August 29, 2015 14:19
久保みどり本 8章 今回は手を動かすというよりも読み物メイン。
library("ggplot2")
library("magrittr")
library("dplyr")
# midori 8
# http://hosho.ees.hokudai.ac.jp/~kubo/ce/IwanamiBook.html
data <- c(4,3,4,5,5,2,3,1,4,0,1,5,5,6,5,4,4,5,3,4)
hist(data)
loglik <- function(q){