Skip to content

Instantly share code, notes, and snippets.

@yuu-ito
yuu-ito / midori_study_7.r
Last active August 29, 2015 14:18
久保みどり本 7章 途中まで。
library("magrittr")
library("dplyr")
library("ggplot2")
# midori_study 7
# http://hosho.ees.hokudai.ac.jp/~kubo/ce/IwanamiBook.html
rsc.dir <- "~/workspace/kubo_midori_7/"
d <- paste0(rsc.dir,"data.csv") %>% read.csv
head(d)
@yuu-ito
yuu-ito / midori_study_6.4_p120.R
Created March 24, 2015 03:03
久保みどり本 p.120 ~ 121 図6.4 ロジスティック関数のパラメタを変化させたときの曲線の動き
# p.120
logistic <- function(z){
1 / (1+exp(-z))
}
# z <- seq(-6,6,0.1)
# plot(z,logistic(z),type="l")
x <- seq(-3,3,0.1)
z <- function(x,b_1,b_2){
# z = b_1 + b_2*x

PureDataに投げるSQLを書く上で気にしていること #vgadvent2014

※これはVOYAGE GROUP エンジニアブログ:Advent Calendar 2014の3日目の記事です。

もうこんな季節なんですね。 去年のエントリから1年経ってると思うとホントにあっという間にでした!

弊社では、運用しているメディアサービスのデータ解析環境としてDWH(データウェアハウス)製品のひとつであるPureData(IBM PureData for Analytics)を使っていたりします。 Amazon RedshiftGoogle BigQuery などのクラウドサービスもあったりするので高性能なシステムでの分析ができる機会は増えてくるのかなと思います。

mysql -uroot -e 'select now(),date(now())' | cat > /tmp/out.txt
more /tmp/out.txt
  • 結果
now()   date(now())
2014-10-06 19:13:44     2014-10-06
@yuu-ito
yuu-ito / ラベルの回転など.R
Last active August 29, 2015 14:07
R/ggplot2/theme/element_text/angle
# http://docs.ggplot2.org/current/theme.html
# http://docs.ggplot2.org/current/scale_date.html
a <- AirPassengers
ap.df <- data.frame(
year=seq(from=as.Date("1949-01-01"),to=as.Date("1960-12-01"),by="1 month"),
passengers=as.numeric(a)
)
p <- qplot(data=ap.df,x=year,y=passengers)+geom_line()+scale_x_date(labels = date_format("%Y/%m/%d"))
print(p)
# -*- coding: utf-8 -*-
# http://docs.python.jp/2/library/unittest.html
# https://pypi.python.org/pypi/pyrg
import random
import unittest
class TestSequenceFunctions(unittest.TestCase):
import datetime
import calendar
def lastday_of_month(date):
y = date.year
m = date.month
last_d = calendar.monthrange(y, m)[1]
return date.replace(day=last_d)
@yuu-ito
yuu-ito / bind.params.r
Last active August 29, 2015 14:05
文字列埋め込みっぽいもの。
bind.params<-function(txt.template,...){
require("dplyr")
loop.cnt <-
txt.template %>%
strsplit(.,"") %>%
unlist %in%
c('?') %>%
which %>%
length
res <- txt.template
@yuu-ito
yuu-ito / 0_test.r
Last active August 29, 2015 14:05
RUnitのメモ
library('RUnit')
source('./mysum.r')
# refs
# - http://cran.r-project.org/web/packages/RUnit/RUnit.pdf
# - http://www.okada.jp.org/RWiki/?RUnit%20%A4%F2%BB%C8%A4%A6
test.mysum <- function(){
checkEqualsNumeric(mysum(1:10),55)
}