Skip to content

Instantly share code, notes, and snippets.

View tsutarou10's full-sized avatar
🏠
Working from home

Tatsuro Miyazaki tsutarou10

🏠
Working from home
View GitHub Profile
@tsutarou10
tsutarou10 / sigmoidBasis.py
Created October 31, 2017 19:12
シグモイド基底関数
#coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
def sigmoid(x,mu,s):
a = (x - mu) / s
return 1 / (1 + np.exp(-a))
if __name__ == "__main__":
@tsutarou10
tsutarou10 / gaussianBasis.py
Created October 31, 2017 19:11
ガウス基底関数
#coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
def phi(x,mu,s):
return np.exp(-(pow(x-mu,2))/(2*pow(s,2)))
if __name__ == "__main__":
N = 1000
@tsutarou10
tsutarou10 / cross_validation.py
Last active September 22, 2017 19:05
交差検定
#coding: utf-8
from sklearn.multiclass import OneVsRestClassifier
from sklearn.svm import LinearSVC,SVC
import numpy as np
from sklearn.metrics import recall_score,precision_score,f1_score
from sklearn import datasets
class SVM:
@tsutarou10
tsutarou10 / fitting.py
Created September 18, 2017 21:39
多項式曲線フィッティング
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import random
from matplotlib import pyplot as plt
def makeData(trainNum):
noise = np.random.randn(trainNum) * 0.1 #make a noise
xTrain = np.random.rand(trainNum) #training data
@tsutarou10
tsutarou10 / taylor.py
Created September 15, 2017 11:01
テイラー展開展開(sin)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from matplotlib import pyplot as plt
def function(x):
return np.sin(x)
def diff(x,n):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from matplotlib import pyplot as plt
def function(x):
return x ** 2 - 4 * x + 4
def diff(x): #数値微分
@tsutarou10
tsutarou10 / multivariate_normal.py
Created August 28, 2017 14:41
ガウス分布 (2次の場合)
#coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
def norm(x,mu,sigma):
return (1 / pow(2 * np.pi,x.shape[0]/2)) * (1 / pow(np.linalg.det(sigma),0.5)) * np.exp(-0.5 * np.dot(x - mu,np.linalg.inv(sigma)).dot(x - mu))
if __name__ == "__main__":
x = np.linspace(-5.0, 5.0, 200)
y = np.linspace(-5.0, 5.0, 200)
@tsutarou10
tsutarou10 / univariate_normal.py
Created August 28, 2017 14:40
ガウス分布 (1次の場合)
#coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
def norm(x,mu,sigma):
return 1 / pow(2*np.pi*sigma,0.5) * np.exp(-0.5*pow(x-mu,2)/sigma)
if __name__ == "__main__":
N = 1000
@tsutarou10
tsutarou10 / betaDistribution.py
Last active August 22, 2017 12:25
ベータ分布
#coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
from scipy.special import gamma
N = 100
alpha = [0.1,1.0,2.0,8.0,10.0]
beta = [0.1,1.0,3.0,4.0,10.0]
@tsutarou10
tsutarou10 / berbernoulliDistribution.py
Created August 18, 2017 01:12
ベルヌーイ分布
#coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.mlab as mlab
def bern(x,p):
return pow(p,x) * pow(1-p,1-x)
if __name__ == "__main__":