Skip to content

Instantly share code, notes, and snippets.

@sinhrks
sinhrks / df_plot_area.py
Created March 17, 2014 20:23
Pandas dataframe line and area plots
import string
from pandas import DataFrame
import numpy as np
from numpy.random import randn, rand
import pandas.tools.plotting as plotting
from matplotlib.pylab import close
@sinhrks
sinhrks / df_plot_legend.py
Created March 21, 2014 07:57
Pandas dataframe with legends
from pandas import DataFrame, Series
from numpy.random import randn, rand
df1 = DataFrame(randn(6, 3), index=range(6),
columns=['a', 'b', 'c'])
df2 = DataFrame(randn(6, 3), index=range(6),
columns=['d', 'e', 'f'])
df3 = DataFrame(randn(6, 3), index=range(6),
@sinhrks
sinhrks / df_plot_bar_2.py
Created March 23, 2014 04:57
Pandas dataframe with centered bar
import string
from pandas import DataFrame, Series
from numpy.random import randn
import matplotlib.pyplot as plt
df = DataFrame(randn(7, 4),
index=list(string.ascii_letters[:7]),
columns=['x', 'y', 'z', 'four'])
series = Series(randn(7), index=range(7))
@sinhrks
sinhrks / df_plot_errorbar.py
Created April 8, 2014 13:19
Pandas plotting with errorbars
# -*- coding: utf-8 -*-
import string
from pandas import DataFrame, Series
import datetime
import numpy as np
from numpy.random import randn, rand
import pandas.tools.plotting as plotting
from pandas.compat import u, string_types
@sinhrks
sinhrks / df_plot_pie.py
Created April 27, 2014 00:45
Pandas plotting with pie
import pandas as pd
import numpy as np
import pandas.util.testing as tm
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
series = pd.Series(3 * np.random.rand(4), index=['a', 'b', 'c', 'd'], name='series')
@sinhrks
sinhrks / KalmanFilter01.R
Last active August 29, 2015 14:08
KalmanFilter (univariate) with ggplot2 animation
set.seed(1)
# 観測系列のサンプルサイズ
n <- 120
# 真の値
actual <- rep(5, out.length = n)
# 観測される値 (誤差は標準偏差2の正規分布とする)
observed <- actual + rnorm(n, mean = 0, sd = 2)
@sinhrks
sinhrks / KalmanFilter02.R
Created November 1, 2014 22:13
KalmanFilter (univariate) with ggplot2 animation Pt2
set.seed(1)
# 観測系列のサンプルサイズ
n <- 200
# 真の値が時間変化する
actual <- 3.0 + cumsum(rnorm(n, sd = 0.2))
# 観測される値 (誤差は標準偏差2の正規分布とする)
observed <- actual + rnorm(n, mean = 0, sd = 2)
@sinhrks
sinhrks / KalmanFilter03.R
Created November 4, 2014 15:26
KalmanFilter (multivariate) with ggplot2 animation
set.seed(1)
# 観測系列のサンプルサイズ
n <- 100
# 真の値
x <- c(rep(0, n / 4), seq(0, 10, length.out = n / 4),
rep(10, n / 4), seq(10, 0, length.out = n / 4))
y <- c(seq(0, 10, length.out = n / 4), rep(10, n / 4),
seq(10, 0, length.out = n / 4), rep(0, n / 4))
@sinhrks
sinhrks / KalmanFilter04.R
Last active August 29, 2015 14:08
KalmanFilter (multivariate) with ggplot2 animation Pt2
set.seed(1)
# 観測系列のサンプルサイズ
n <- 30
# 加速度
a <-rep(0.3, n)
v <- cumsum(0.5 * a)
x <- cumsum(v)
@sinhrks
sinhrks / logit.py
Last active August 29, 2015 14:10
Logistic Regression
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
# rpy2 経由で R から iris をロード
# import pandas.rpy.common as com
# iris = com.load_data('iris')