Skip to content

Instantly share code, notes, and snippets.

@aita
aita / gist:5890119
Last active December 19, 2015 03:28
foreign-regexp の使い方メモ

foreign-regexp

正規表現をたしかめる:M-x re-builder
正規表現をコピーする:C-c C-w
re-builderの終了:C-c C-q
正規表現を用いて置換:M-s M-% (foreign-regexp/query-replace)
@aita
aita / gist:5891010
Created June 29, 2013 12:57
ベイジアンフィルタ
# -*- coding: utf-8 -*-
import sys, math
from collections import defaultdict
import requests
from lxml import etree
APP_ID = '*****'
API_URL = "http://jlp.yahooapis.jp/MAService/V1/parse";
DEFAULT_FILTER = (1,2,3,4,5,9,10)
import csv
import math
import numpy as np
import matplotlib.pyplot as plt
from collections import defaultdict
DATA = [
(400, 60),
(15, 30),
(480, 365),
@aita
aita / gist:5895085
Created June 30, 2013 13:08
相関係数の算出
import csv
import math
import numpy as np
import matplotlib.pyplot as plt
from collections import defaultdict
DATA = [
(400, 60),
(15, 30),
(480, 365),
@aita
aita / gist:5895106
Created June 30, 2013 13:14
算術平均と幾何平均
import numpy as np
from scipy.stats import gmean
d1 = [2,4,5,7]
d2 = [2,4,5,70]
print np.average(d1), np.average(d2)
print gmean(d1), gmean(d2)
@aita
aita / gist:5898382
Created July 1, 2013 04:36
ポアソン分布
import matplotlib.pyplot as plt
import numpy as np
l = 5
sample = 10000
data = np.random.poisson(l, sample)
n, bins, patches = plt.hist(data, bins=14, normed=True)
plt.show()
@aita
aita / gist:5898538
Created July 1, 2013 05:26
歪度と尖度
import scipy.stats
import numpy as np
import scipy as sp
DATA = [
(400, 60),
(15, 30),
(480, 365),
(993, 190),
(600, 136),
import scipy.stats
import scipy as sp
data = [3, 4, 5, 2, 3, 4, 5, 6, 4, 7]
print sp.stats.skew(data) # 0.303193339354
@aita
aita / gist:5898640
Created July 1, 2013 05:51
標準化変量の計算
import scipy.stats
import numpy as np
import scipy as sp
DATA = [
(400, 60),
(15, 30),
(480, 365),
(993, 190),
(600, 136),
@aita
aita / gist:5899303
Created July 1, 2013 08:40
標本分布
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import numpy as np
sample = 10000
mu, std = 0, 10
data = [np.mean(np.random.normal(mu, std, sample)) for x in range(sample)]
n, bins, patches = plt.hist(data, bins=50, normed=True)