This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import PolynomialFeatures | |
import numpy as np | |
from sklearn import linear_model, grid_search | |
import matplotlib.pyplot as plt | |
X = np.linspace(-10, 10, 20) | |
Y = 0.001 * (X*X*X + X*X + X) + np.random.normal(0, 0.1, len(X)) | |
poly = PolynomialFeatures(degree=10) | |
X_poly = poly.fit_transform(X[:, np.newaxis]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pystan | |
import numpy as np | |
import matplotlib.pyplot as plt | |
mean1 = 10 | |
mean2 = -10 | |
mean3 = 0 | |
num1 = 200 | |
num2 = 300 | |
num3 = 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data { | |
int<lower=1> N; | |
int<lower=1> k; | |
real X[N]; | |
} | |
parameters { | |
simplex[k] theta; | |
real mu[k]; | |
} | |
model { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymc as pm | |
import numpy as np | |
ndims = 2 | |
nobs = 20 | |
n = 1000 | |
y_sample = np.random.binomial(1, 0.5, size=(n,)) | |
x_sample=np.empty(n) | |
x_sample[y_sample==0] = np.random.normal(-1, 1, size=(n, ))[y_sample==0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pymc as pm | |
import numpy as np | |
x_sample = np.random.normal(loc=1.0, scale=1.0, size=1000) | |
with pm.Model() as model: | |
mu = pm.Normal('mu', mu=0., sd=0.1) | |
x = pm.Normal('x', mu=mu, sd=1., observed=x_sample) | |
with model: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 主成分分析による次元削減 | |
# 共分散行列を求める | |
X_bar = np.array([row - np.mean(row) for row in X.transpose()]).transpose() | |
m = np.dot(X_bar.T, X_bar) / X.shape[0] | |
# 固有値問題を解く | |
(w, v) = np.linalg.eig(m) | |
v = v.T | |
# 固有値の大きい順に固有値と固有ベクトルをソート |