2019-03-01から1ヶ月間の記事一覧

線形回帰の指数関数

# Y = alpha + beta * x # 下の式を上に変換 # y = a * exp(b * x) # Y = log(y), a = exp(alpha), b = beta x = np.array([-2.1, -1.3, -0.4, 0.1, 0.6, 1.2, 1.6, 1.9]) y = np.array([0.5, 0.7, 1.0, 1.5, 3.2, 4.6, 5.0, 6.8]) Y = np.log(y) s_cov = np…

Python の線形回帰(信頼区間95 %)

アットマーク@ は .dot() の代わりらしい(内積)。 np.array([1,2]) @ np.array([2,3]) 単回帰について from sklearn.linear_model import LinearRegression X = np.array([167, 168, 168, 183, 170, 165, 163, 173, 177, 170]) y = np.array([59, 58, 65, …

χ二乗検定と独立性の検定

from scipy import stats, integrate l = np.array([4,4,22,26,36,45,39,21,16,4]) score_l = np.arange(5, 105, 10) # 標本平均と不変標本分散 mu = (l * score_l).sum() / l.sum() sigma2 = ((l * ((score_l-mu)**2)).sum() / (l.sum()-1)) # 確率プロット…

python の仮説検定

a = np.array([70, 69, 72, 74, 66, 68, 69, 70, 71, 69, 73, 72, 68, 72, 67]) b = np.array([69, 72, 71, 74, 68, 67, 72, 72, 72, 70, 75, 73, 71, 72, 69]) a.mean(), b.mean() # (70.0, 71.13333333333334) sgm = (a.var() * len(a) + b.var() * len(b)…

信頼区間の コード

import numpy as np from scipy import stats import statsmodels as sms # 例 a = np.array([12.7,6.6,5.6,14.3,11.4,10.8,13.8,11.2,10.0,12.8,7.1,14.0]) # 正規分布の標本と仮定したときの、母平均の信頼区間 sigma = np.sqrt(dev / len(a)) stats.norm.…

クラス別の割合

クラス別の割合について、seaborn のこれ使ったら便利 import pandas as pd import seaborn as sns # バイオリンプロット sns.violinplot(x = 'target', y = 'rate', data = df) # 箱髭プロット(直感的な図だが、詳細が不明) sns.boxplot(x = 'target', y …

Mysql 5.7 で 767 byte 以上のインデックスが貼れた

longtext にインデックスを貼ろうとしていた。 alter table `table` add index `index_name` (`name`(256)); 以下がでなかった Specified key was too long; max key length is 767 bytes なるほど mysql> SHOW GLOBAL VARIABLES LIKE 'innodb_large_prefix%…

コサイン距離系

コサイン類似度を求めるためには、 sklearn.metrics.pairwise.cosine_similarity の方。 sklearn.metrics.pairwise.cosine_similarity — scikit-learn 0.20.3 documentation docs.scipy.org