ビジネス書大賞2014年
松原先生と言えば、大学1年の時に統計の講義をとっていた!
実は、現在でもいまだに「統計学はよくわからない」という印象が残ったままである。
# 必要なものをimport
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn
def set_fig():
# プレゼン用
plt.figure(figsize=(10,6))
plt.xticks(fontsize=20)
plt.yticks(fontsize=20)
set_fig()
# まずは乱数を発生させるところから
# 0から1の間の小数を1,000個(一様分布)
uniform_rand = np.random.uniform(0,1,1000)
_ret = plt.hist(uniform_rand, bins = 50)
# 10個ずつまとめる(100行10列のデータに変形)
uniform_reshape = uniform_rand.reshape(100,10)
print(uniform_reshape.shape)
print(uniform_reshape)
(100, 10) [[ 4.89373787e-01 4.66742987e-01 2.65512742e-01 8.92802517e-01 8.40520626e-01 6.23913915e-01 3.51831140e-01 4.26837659e-01 9.69985783e-02 2.82317913e-01] [ 6.73753855e-01 5.37307334e-01 5.54695278e-01 8.38060370e-01 8.68602544e-02 3.01000327e-01 3.73459458e-01 7.51210596e-01 5.80790645e-01 6.12339747e-02] [ 9.36138150e-01 1.24612373e-01 2.97114741e-01 5.80622613e-01 9.37362917e-01 5.29324664e-01 7.06195664e-01 3.06701047e-01 4.40829105e-01 3.68885474e-01] [ 7.75664640e-01 8.91042122e-01 1.30042195e-01 7.20586248e-01 7.72328418e-01 6.37321342e-01 4.22910733e-01 5.45322382e-02 3.89045246e-01 4.30436898e-01] [ 7.80936820e-01 4.47696464e-01 2.85232755e-01 2.96296733e-01 7.83841872e-01 5.91644344e-03 1.92951246e-01 9.43487743e-01 9.03880830e-01 7.72332038e-02] [ 9.73335009e-01 8.81778924e-01 3.51626083e-01 2.20974948e-01 6.13244274e-01 5.37882250e-01 5.55440562e-01 4.84477693e-01 5.62076678e-01 2.53738636e-02] [ 1.13158894e-01 9.98615854e-02 2.38757340e-01 5.17983886e-01 6.90969557e-01 3.16463801e-01 1.37511638e-01 6.78068631e-01 3.33625601e-01 6.92769651e-01] [ 2.21971338e-02 7.97961469e-01 7.67543795e-02 9.92408762e-01 5.23875054e-01 5.82931586e-01 5.14652905e-01 9.59222189e-01 2.46279054e-01 6.15875965e-02] [ 1.33323695e-01 4.78068179e-02 3.89148165e-01 1.38236865e-01 6.75426640e-01 3.41333448e-01 1.82740761e-01 8.74177861e-01 5.33765970e-01 4.89635159e-02] [ 9.00049460e-01 3.51224913e-01 1.81036213e-01 3.98518427e-03 2.19698462e-01 4.66652478e-01 2.52469763e-01 6.12538299e-01 1.98155550e-01 2.67483845e-01] [ 6.60127035e-01 2.94485354e-01 7.79867917e-02 9.58073409e-01 5.27317871e-01 8.94858419e-01 5.86758753e-01 8.52209099e-01 7.67890835e-01 5.14348546e-01] [ 4.18346188e-01 8.42830785e-01 8.68426814e-01 6.38591183e-01 5.53656177e-01 4.00704093e-01 5.89076867e-01 3.60167220e-01 2.62704897e-01 9.35901398e-01] [ 3.58686412e-01 8.99823191e-01 7.71794065e-01 7.74741030e-01 1.19914503e-01 8.90928337e-01 9.06522942e-01 3.89180002e-01 9.84367767e-01 6.32525015e-01] [ 9.01832519e-01 3.53964183e-01 9.04913408e-01 9.85615594e-01 3.17134982e-01 8.83933580e-02 9.69787251e-01 2.25617813e-01 6.00020722e-01 3.15183020e-01] [ 8.02535695e-01 3.23024196e-01 4.22146356e-01 3.65115060e-01 3.23956341e-01 4.98256271e-01 6.79940543e-01 1.12058816e-01 3.79537790e-01 4.50500851e-01] [ 2.36596634e-01 3.16733295e-01 6.84296362e-01 6.98317314e-01 5.80065099e-01 4.69302648e-01 3.90130150e-01 4.64666271e-01 1.21704107e-01 7.12544746e-01] [ 4.74456238e-01 3.92331547e-01 6.45129874e-01 6.71898697e-01 5.02664332e-02 8.01599949e-01 3.97626077e-02 9.73802570e-01 9.76821071e-01 8.67631478e-01] [ 5.46786464e-01 4.11663693e-01 1.01879916e-02 8.35989852e-01 5.94919647e-01 5.50250492e-01 7.32963458e-03 4.72767643e-01 7.22168007e-01 3.86670625e-01] [ 3.58230779e-01 1.87194551e-01 7.95680695e-01 1.12108282e-01 5.65856108e-01 1.84141413e-01 3.96949331e-01 1.36239097e-01 6.90801771e-01 5.02768844e-01] [ 7.13522892e-01 6.83009310e-01 1.75561238e-01 8.23336808e-01 8.00140653e-01 6.99352297e-01 8.71814290e-01 5.42098709e-01 8.92490255e-01 3.44595198e-01] [ 3.47486430e-01 4.70799449e-01 6.26106831e-01 1.14466175e-02 7.90541369e-01 5.61744353e-01 9.42370077e-01 2.18708249e-01 3.39006976e-01 6.44410039e-01] [ 8.03764633e-01 2.26129758e-01 7.39835870e-01 5.07241623e-01 1.64388242e-02 8.13040030e-01 4.41833404e-01 2.54967449e-02 9.47051094e-01 4.72759718e-02] [ 2.02619925e-01 4.83550020e-01 6.86611023e-01 8.37732291e-01 6.95938085e-01 8.88018212e-01 5.41885777e-01 8.33852634e-01 9.91367039e-01 4.65155473e-01] [ 7.84122295e-01 4.18846116e-01 5.99866562e-01 2.80157110e-01 4.26118438e-01 6.78995921e-01 2.12121272e-01 8.87530077e-01 4.98452276e-01 8.98198367e-01] [ 3.87563968e-01 6.03853090e-01 4.09739075e-04 3.74040078e-01 8.50713322e-01 5.48833172e-01 6.09009665e-01 7.15528529e-01 4.86638023e-01 9.09238745e-01] [ 3.89983456e-01 8.08148148e-01 2.12431683e-01 7.25496906e-01 3.33724627e-01 1.73123263e-01 9.02653468e-01 4.83915452e-01 4.61403316e-01 2.84733649e-01] [ 2.16210471e-01 8.76276168e-01 4.43625278e-01 9.81909805e-01 3.94846045e-01 6.21428514e-01 6.35179182e-01 8.90600883e-01 3.39944212e-01 1.80608099e-02] [ 3.49444697e-01 3.43491102e-01 7.45639646e-01 8.78098860e-01 4.54795512e-01 3.52192003e-01 4.16376609e-01 7.21104636e-01 4.76988502e-01 7.28728613e-01] [ 4.92079711e-01 6.17197115e-01 4.83032127e-01 1.00741123e-01 1.74581443e-01 7.68334911e-01 9.38013687e-01 9.91211166e-01 5.78200888e-01 8.07040349e-01] [ 2.03597998e-01 7.97222443e-01 2.19737952e-02 9.61690469e-01 5.94576376e-02 2.88148749e-02 3.80139790e-01 2.42641898e-02 5.49773709e-01 2.14198759e-01] [ 3.54610966e-01 4.54872422e-01 5.08574947e-01 1.68494287e-01 3.26216157e-01 5.77573981e-01 6.63966291e-01 4.96431711e-01 8.92295641e-01 8.21733825e-01] [ 7.95098866e-01 4.65429740e-01 1.98401462e-01 5.81021139e-01 9.47951287e-01 3.47006119e-01 9.85913752e-01 5.81857327e-01 8.66596840e-01 6.05216974e-01] [ 9.00741210e-01 3.93470714e-01 6.25484277e-02 3.81430684e-01 6.61533454e-01 4.47540986e-01 3.12941245e-02 7.21658204e-01 9.11893633e-01 1.50110276e-01] [ 8.81347984e-01 3.15802943e-01 3.32402432e-01 3.30102267e-01 7.48019744e-02 7.45379059e-01 8.23135692e-01 2.60981478e-01 3.68853535e-01 2.29436152e-01] [ 6.31118489e-01 2.28831354e-01 1.68238586e-01 1.08365248e-01 1.42874186e-01 4.29027745e-01 5.10002812e-01 1.79428076e-01 9.19475508e-01 8.94988773e-01] [ 3.80725335e-01 8.24330019e-01 4.55836239e-01 6.77990017e-01 7.10976778e-01 2.32972366e-01 4.33811799e-01 4.50439061e-01 5.07160020e-01 1.56715791e-02] [ 3.16605041e-01 4.54115713e-01 8.21128637e-01 1.15913020e-02 2.38355785e-01 8.01239783e-01 2.69016807e-01 3.40531480e-01 3.52564221e-01 1.62875597e-01] [ 6.65082961e-01 7.19166817e-01 7.42253278e-01 3.89705965e-01 6.91157146e-01 3.84551493e-01 7.69298207e-02 4.26955251e-01 8.46987943e-01 4.86727139e-01] [ 6.15013720e-01 7.39675473e-01 5.79976965e-01 9.85814099e-01 9.69917781e-01 3.81147864e-01 4.50040692e-02 5.84959166e-01 9.99241170e-01 9.47026943e-01] [ 1.45346646e-01 9.14034096e-01 5.98956793e-01 6.92098973e-01 5.20791533e-01 3.72558110e-01 6.06498326e-01 8.23878331e-01 6.62373609e-01 7.64160749e-01] [ 5.97180300e-01 8.85060979e-01 3.55824786e-01 8.88634467e-02 7.51368822e-01 5.74355846e-01 2.23938128e-01 7.82255048e-01 1.73299533e-02 8.08706120e-02] [ 4.61048817e-01 2.48648858e-01 2.91542431e-01 2.29810389e-01 9.83422285e-01 6.24426167e-01 8.05515165e-01 6.72160071e-01 8.10170602e-01 7.87659004e-01] [ 4.53706628e-01 2.73454241e-02 1.84513269e-01 8.51075087e-01 1.83310191e-01 5.50202335e-01 5.69209999e-01 4.57564789e-01 1.58515123e-01 4.52495277e-01] [ 6.98663547e-01 3.14676335e-01 9.09650197e-01 8.55993451e-01 3.80451701e-01 4.91544512e-01 2.33711870e-01 8.06974024e-01 6.42923649e-01 8.11565633e-01] [ 5.56564708e-01 3.72206727e-01 1.84384908e-01 7.93128732e-01 6.76356576e-01 5.27672750e-01 9.10646351e-01 4.68867189e-01 7.31514026e-01 2.17474647e-01] [ 3.90648974e-01 5.68820421e-01 2.65902665e-01 4.68560331e-01 2.10748956e-01 5.84436028e-01 7.99387722e-01 1.07339502e-01 4.94009020e-01 7.91924327e-01] [ 2.95664250e-02 8.01285486e-01 1.26657359e-01 4.52739226e-01 9.49109755e-01 7.60709005e-01 1.23187893e-01 6.08422570e-01 8.06431183e-01 4.19234996e-01] [ 4.75251459e-01 1.80418395e-01 6.63719583e-02 5.62983775e-01 3.43432147e-01 2.55719933e-01 8.70712870e-01 9.36531524e-01 2.27017678e-01 1.97127313e-01] [ 6.87972593e-01 8.31929032e-01 7.32308315e-01 1.60555626e-01 1.61260738e-02 7.40955298e-01 4.02794938e-01 1.90013261e-01 4.66206539e-01 5.03756449e-01] [ 9.93584282e-01 4.99682963e-01 2.54317629e-01 4.73015649e-01 8.87539789e-01 2.49694862e-01 6.32466622e-01 2.57288907e-01 2.49045963e-02 5.19010169e-01] [ 1.87908654e-01 7.71237310e-01 3.70028310e-01 7.17903218e-01 9.06257900e-01 3.93384087e-01 7.62566833e-01 7.64330378e-01 4.60207413e-01 1.77249801e-01] [ 2.75561246e-01 9.49055632e-01 1.67285998e-01 5.94096418e-01 7.94610075e-02 6.76965104e-01 2.09219663e-01 8.14011781e-01 9.45121624e-01 8.28003177e-01] [ 9.70859700e-01 9.40965008e-02 2.03035709e-02 7.85695317e-02 4.96147965e-01 1.71725033e-01 5.07466407e-01 3.22777835e-01 8.83805482e-01 9.49421806e-01] [ 7.78627053e-01 6.98186956e-01 3.63629027e-01 8.72741337e-03 8.61753836e-01 5.15477044e-02 8.74569422e-01 8.22483404e-02 3.87369724e-01 8.89795455e-01] [ 2.32892872e-01 2.63232556e-01 3.09901576e-01 8.43506492e-01 5.98955109e-01 3.14789280e-01 4.27428844e-02 7.33254081e-02 7.81770081e-01 8.95823055e-01] [ 3.68879434e-03 3.68369031e-01 1.32873078e-01 6.83796747e-01 9.90228349e-01 5.81701989e-01 6.74027526e-01 2.92619126e-01 9.36800390e-01 5.71375919e-02] [ 2.49140953e-01 3.83421408e-01 1.97599366e-04 1.92051029e-01 4.15041468e-01 5.10755426e-01 2.25639801e-01 6.50809399e-01 7.55350064e-01 9.38854855e-01] [ 1.26454230e-01 4.47947693e-01 5.33825509e-01 9.02405328e-01 2.07766492e-01 8.50597556e-01 3.31317383e-01 8.38896189e-01 2.25597823e-01 9.89065360e-01] [ 7.15507207e-01 1.73078323e-01 6.10296670e-01 5.11339857e-01 5.02443234e-01 1.69114907e-01 5.46211040e-01 7.12592618e-01 7.76241478e-01 8.23272744e-01] [ 3.54192863e-01 1.71106493e-01 2.67614304e-01 6.30132975e-01 3.70050032e-01 1.06294846e-01 4.98171142e-01 1.19559685e-01 1.69026171e-01 1.91887153e-01] [ 1.31366987e-01 8.35168612e-01 6.14590587e-01 4.28281413e-01 5.35530072e-01 9.62791313e-01 4.80770702e-01 9.35258294e-01 8.18613348e-01 3.29417727e-01] [ 3.74921712e-01 2.25643911e-01 4.69409824e-01 4.06840272e-01 3.51377355e-01 2.72750147e-01 5.21221850e-01 6.31960132e-01 3.35420065e-01 8.14973891e-01] [ 6.02386558e-01 6.82313303e-01 4.80257164e-01 5.90316227e-02 2.73316321e-01 3.25794374e-01 3.85593584e-01 1.81315821e-01 8.36237508e-01 6.11256212e-01] [ 3.26733934e-01 1.98023128e-01 2.07164275e-01 4.36719653e-01 8.81293669e-01 3.83424242e-01 4.60314128e-01 2.61399629e-01 5.31472478e-01 4.20079313e-01] [ 1.32997381e-01 3.19256834e-01 4.51275462e-01 3.17182774e-01 1.98405077e-01 2.24698606e-01 8.04789745e-01 7.88759677e-01 9.97941838e-01 3.73643512e-01] [ 8.19112914e-01 7.79831576e-01 9.81258793e-01 4.15091111e-01 1.78258616e-02 5.44972151e-01 8.64205974e-01 8.39760436e-01 3.40112815e-01 5.28186585e-02] [ 3.22161996e-01 9.43413131e-02 7.07445952e-01 2.82555589e-01 3.18737169e-02 4.33625300e-01 5.79526455e-01 2.78821585e-01 8.33460857e-01 9.06019242e-01] [ 7.54518885e-01 6.57029434e-01 1.39976741e-01 8.14576561e-01 4.75566749e-01 3.47133139e-02 7.53283429e-01 8.59308034e-01 8.85162673e-01 7.34894327e-01] [ 2.70568316e-01 4.41217526e-01 2.07945848e-02 9.81656194e-01 9.56658773e-01 2.18028805e-01 3.80372218e-01 6.93360868e-01 7.10425917e-01 3.03923565e-01] [ 8.21165895e-01 2.11318210e-01 1.22992936e-01 8.23215113e-02 7.11209491e-01 8.96557851e-01 3.98736724e-01 7.33608517e-01 8.36361362e-01 3.37198249e-01] [ 1.43129923e-01 3.00985641e-01 3.63956520e-01 8.34987541e-01 9.37248298e-01 6.90202973e-01 7.22576384e-01 7.03324667e-01 3.36881078e-01 1.32731858e-01] [ 2.81500529e-01 5.78724809e-01 8.52100914e-01 9.93034865e-01 3.07873635e-01 9.09525302e-01 6.21825017e-01 1.04640702e-01 4.18862266e-01 1.76018119e-01] [ 7.26545875e-01 6.87355509e-01 8.92892797e-01 1.60383227e-01 7.14146926e-01 4.39561652e-01 6.57552014e-01 4.56524711e-01 8.61421016e-01 5.80489434e-02] [ 4.06560970e-01 3.93827621e-01 5.60249001e-01 5.08952584e-01 1.13203131e-01 2.94128243e-01 9.47348924e-01 4.25292566e-01 6.37149031e-03 8.84449878e-01] [ 3.60195151e-01 2.91276042e-02 7.72618172e-01 5.60991459e-01 7.05997443e-01 1.24626355e-01 8.38762223e-01 3.87586377e-01 8.40330687e-01 5.14717470e-01] [ 8.86318636e-01 2.03720082e-01 9.67087093e-01 9.06472080e-02 9.90987438e-02 3.31484253e-01 4.31239443e-01 1.49220822e-01 4.10981387e-02 1.23194929e-01] [ 2.40126113e-01 5.36107858e-01 1.48049848e-01 5.81401634e-01 3.84888488e-01 9.64189582e-01 8.14638949e-01 4.46027874e-01 3.11619778e-01 7.43892587e-01] [ 7.15183060e-01 4.18650674e-01 9.16900123e-01 2.55653926e-01 7.05398442e-02 7.61730643e-01 3.03179456e-01 3.16286333e-01 2.75762957e-02 7.29636296e-01] [ 7.10126513e-01 7.22104910e-01 9.01342866e-01 5.00197924e-01 4.33152120e-02 9.86357430e-01 6.00353488e-01 2.71956159e-01 7.21063806e-01 1.39846867e-01] [ 9.86421713e-01 8.10400544e-01 1.01493816e-01 3.78392164e-01 4.07687626e-01 9.38426395e-01 2.34503523e-01 6.84754703e-01 5.46860234e-01 1.13924081e-01] [ 5.76616207e-02 1.69214445e-01 9.40497761e-01 7.13344933e-01 5.97386596e-01 1.77325825e-01 3.10864512e-01 7.19681654e-01 1.84973142e-01 3.09682031e-01] [ 6.53146715e-01 1.65844325e-02 4.49616642e-01 4.63864061e-01 5.28687676e-01 3.92610311e-01 6.54854229e-01 5.62878841e-01 3.35582572e-02 1.14637325e-01] [ 5.13527846e-02 4.79516923e-01 6.86837383e-01 5.84762097e-01 8.13292444e-02 4.04887604e-01 5.03866243e-01 5.48737942e-01 3.36665353e-01 8.50705573e-01] [ 5.06391888e-01 1.99807205e-01 5.56457307e-01 5.09297257e-01 9.44579811e-01 1.74087330e-01 6.21774984e-01 6.65350182e-01 5.51920730e-01 8.27762045e-01] [ 1.68550000e-01 2.27610835e-01 1.17395788e-01 1.65576942e-01 4.41184805e-01 2.45982248e-01 1.42759338e-01 9.08397514e-01 4.98816660e-01 5.40776676e-01] [ 6.35369683e-01 6.41260310e-01 7.99940149e-01 4.06273783e-01 9.05012102e-01 3.81647876e-01 7.21158243e-01 2.95952354e-01 8.61558490e-02 9.82895099e-02] [ 2.55604582e-01 3.11873471e-01 5.53437095e-02 7.74498791e-01 2.19105469e-01 7.66073548e-01 4.08322369e-01 1.54938338e-01 6.29352549e-01 2.13994756e-01] [ 9.85778502e-01 4.82004862e-01 3.83494142e-01 2.79825542e-01 4.34622457e-01 4.26922782e-01 1.34971956e-01 2.82356198e-01 3.88165017e-01 9.71409013e-01] [ 4.22378952e-02 7.60801817e-01 4.84468598e-01 4.59863241e-01 3.62759482e-01 4.49827386e-01 7.24454962e-01 7.25404778e-01 7.90620238e-01 9.99087340e-02] [ 4.06301111e-01 8.93455095e-01 2.38913482e-01 8.60351710e-01 2.83478322e-01 4.42536585e-01 9.03051982e-01 4.06785369e-01 6.51046918e-01 8.01189864e-01] [ 8.26932898e-01 9.62355562e-01 4.78462892e-01 8.85657994e-03 8.81350546e-01 4.17886007e-01 1.27199663e-01 7.50782199e-01 9.80979081e-01 9.47872405e-01] [ 6.75428099e-02 5.23128365e-01 4.41213684e-01 1.99579299e-01 6.86487949e-01 3.82714462e-03 4.89676260e-01 6.39592544e-01 6.76338399e-01 9.06912868e-02] [ 8.92266045e-02 6.11850275e-01 6.56301718e-01 9.74636928e-01 3.70095239e-01 4.43241237e-01 3.75618797e-01 4.57658998e-02 3.57148195e-01 8.79082257e-01] [ 9.40893273e-01 2.34827528e-01 1.46969551e-01 8.43478197e-01 6.29800258e-01 6.46713017e-02 4.85463548e-01 4.21998497e-01 1.84065996e-01 4.03600052e-02] [ 3.92770514e-01 3.59242861e-02 7.80424191e-01 6.40771108e-01 5.79175668e-01 4.16974914e-01 6.76258079e-01 2.28250366e-01 5.67731166e-01 3.37784927e-01] [ 7.79895384e-01 7.23893796e-02 6.85105138e-01 3.66882141e-01 6.46803783e-01 4.21481369e-01 3.93782108e-01 4.50769798e-01 6.14713482e-01 3.10731093e-01] [ 8.78083469e-01 1.86853571e-01 3.61303402e-01 9.46667917e-01 3.62527596e-01 7.28523661e-01 7.51055133e-01 2.58128652e-01 1.98411130e-01 3.63565025e-01] [ 7.46631905e-01 1.81006924e-01 7.35164878e-01 5.68448970e-01 1.58735192e-01 5.72265734e-01 8.37714282e-01 3.08716039e-01 1.42985408e-01 3.19057212e-01] [ 9.17419082e-01 3.39851621e-01 1.71538254e-01 4.42358024e-01 8.48472735e-01 5.99241055e-01 3.80710914e-01 9.27347621e-01 2.31326207e-01 9.36315959e-01] [ 3.61397511e-01 7.42627850e-01 5.44911127e-03 8.35850764e-01 6.90746439e-01 8.81484573e-01 9.45888642e-01 9.92539213e-01 1.64338459e-01 8.91302042e-01]]
# そして、その10個の平均をとる(100個のデータになる)
uniform_avg10 = uniform_reshape.mean(1)
print(uniform_avg10.shape)
print(uniform_avg10)
(100,) [ 0.47368519 0.47583721 0.52277867 0.52239101 0.47174741 0.52062103 0.38191706 0.47778701 0.33649237 0.34532942 0.61340561 0.58704056 0.67284833 0.56624629 0.43570719 0.46743566 0.58937005 0.4538734 0.39299709 0.65459217 0.49526204 0.4568108 0.66267305 0.56844084 0.54858283 0.4775614 0.54180814 0.54668602 0.59504325 0.32411337 0.52647702 0.63744935 0.46622217 0.43622435 0.42123508 0.46899132 0.37680244 0.54295178 0.68477773 0.61006972 0.43570479 0.59144038 0.38879381 0.61461549 0.54388166 0.46817779 0.50773439 0.41155671 0.47326181 0.47915055 0.55110739 0.55387816 0.44951738 0.49964549 0.43569393 0.47212426 0.4321262 0.54538736 0.55400981 0.28780357 0.60717891 0.44045192 0.44375025 0.41066244 0.46089509 0.56549903 0.4469832 0.61090301 0.49770068 0.51514707 0.51660249 0.52441062 0.56544327 0.45403844 0.51349529 0.33231093 0.51709427 0.45153367 0.55966652 0.52028648 0.41806325 0.38704385 0.45286611 0.55574287 0.34570508 0.49710599 0.37891076 0.47695505 0.49003471 0.58871104 0.63826778 0.38180777 0.48029672 0.39925282 0.46560652 0.47425537 0.50351196 0.45707265 0.57945815 0.65116246]
set_fig()
# ヒストグラムを描く
_ret = plt.hist(uniform_avg10)
もとのこの分布の真ん中(0.5)を中心とした正規分布が出てくる。
ちなみにこれが正規分布の確率密度関数
$$ f(x, \mu,\sigma) = \frac{1}{\sigma\sqrt{2\pi}}e^{-\frac{(x-\mu)^2}{2\sigma^2}} $$イカツイ・・・
基本が大切
平均 $$ \mu = \frac{1}{n} \sum_{i=0}^{n}{x_{i}} $$ 分散 $$ \sigma^2 = \frac{1}{n} \sum_{i=0}^{n}{(x_{i}-\mu)^2} $$ 標準偏差 $$ \sigma = \sqrt{\sigma^2} $$
set_fig()
# 平均0、分散1の正規分布に従う乱数100個
normal_rand = np.random.normal(0, 1, 100)
_ret = plt.hist(normal_rand)
set_fig()
# もっと綺麗な正規分布が描きたいときは、
from scipy import stats
# 便宜的に領域を決めてXをつくる
X = np.arange(-4,4,0.01)
# 値を計算します。
Y = stats.norm.pdf(X,0,1)
# PDF:Probability Density Function 確率密度関数
plt.plot(X,Y)
[<matplotlib.lines.Line2D at 0x109694828>]
set_fig()
plt.plot(X,Y)
# 全体の面積は1、-2から2までは?
print(stats.norm.cdf(2,0,1)-stats.norm.cdf(-2,0,1))
0.954499736104
set_fig()
# CDF:Cumulative Distribution Function 累積分布関数
Y = stats.norm.cdf(X)
plt.plot(X,Y)
[<matplotlib.lines.Line2D at 0x1099efc50>]
set_fig()
# boxplotを使ったデータの可視化
_data0 = np.random.normal(0, 1,100)
_data1 = np.random.normal(1, 1.5,100)
data = pd.DataFrame( [_data0, _data1]).T
data.columns = ['mu=0_std=1.0', 'mu=1_std=1.5']
_ret = data.boxplot(return_type='dict', fontsize=20) # 警告抑止のため
set_fig()
seaborn.violinplot(data=data)
<matplotlib.axes._subplots.AxesSubplot at 0x10a26ad68>
set_fig()
# 平均0と平均2の2つの正規分布から乱数を発生させる
_data0 = np.random.normal(0, 1,100)
_data1 = np.random.normal(5, 1,100)
dual_normal = np.concatenate((_data0, _data1))
_ret = plt.hist(dual_normal,bins=20)
set_fig()
# 分布の詳細な形がわからなくなる
_ret = plt.boxplot(dual_normal)
set_fig()
# ヴァイオリンプロットだと分布の情報が消えない
seaborn.violinplot(dual_normal, orient='v')
<matplotlib.axes._subplots.AxesSubplot at 0x10a43fc50>
またの機会に、検定とかの話もしてみたいと思います