統計検定の
データセットは、
データセット
イギリスの
訪問回数 | 回答数 |
---|---|
1回目 | 84 |
2回目 | 18 |
3回目 | 12 |
4回目 | 4 |
5回目 | 12 |
6~9回目 | 5 |
10~19回 | 7 |
20回以上 | 12 |
前提
Bokeh と
- Bokeh
% python3 -m pip list | grep bokeh bokeh 0.12.16
holoviews
bokeh0.12.16
で、graph描画する 方法が 見つけられず、 holoviews 経由で 描画したので、 holoviewsも インストールして おります。 holoviews 1.10.4
Ploty
% python3 -m pip list | grep plotly plotly 2.7.0
ヒストグラムに ついて
そもそも、
ヒストグラム - Wikipedia
Wikipediaメトリクスを
用いた ソフトウェア品質定量評価・改善 (GQM, Metrics, ET2013) ソフトウェアの 品質観点で、 サイクロマチック複雑度の ヒストグラムが 記載されていました。 ソフトウェア品質知識体系ガイド(第2版)-SQuBOK Guide V2- - Google ブックス
SQuBOK ガイドの第2版 の 335 ページに 以下のように 記載されています。 データの
ばらつきを 把握したり、 分布の 特徴を 見たり、 規格値と データの 関係を 見たりする ために 用いる、 データの 度数分布を 表示した 柱状図。 Googleスプレッドシートで
ヒストグラム(Excelは 大変なので ) - Akiyahの 日記
Google スプレッドシートでのヒストグラムの 書き方
Bokeh で ヒストグラムを 描画する
まず、
調べた
警告が
import numpy as np import holoviews as hv import random hv.extension('bokeh') # ヒストグラムの値 区間決定後の値 を np.repeat、np.concatenate を使って再度集計 values = np.concatenate([np.repeat([1], 84), np.repeat([2], 18), np.repeat([3], 12), np.repeat([4], 4), np.repeat([5], 12), np.repeat([random.randint(6,9)], 5), np.repeat([random.randint(10,19)], 7), np.repeat([random.randint(20,20)], 12)], axis=0) frequencies, edges = np.histogram(values, 20) # options で グラフの幅を指定 hv.Histogram(frequencies, edges).options(width=600)
WARNING:root:Histogram: Histogram edges should be supplied as a tuple along with the values, passing the edges will be deprecated in holoviews 2.0.
Plotly で 描画する
これは、
import numpy as np import holoviews as hv import random hv.extension('plotly') # ヒストグラムの値 区間決定後の値 を np.repeat、np.concatenate を使って再度集計 values = np.concatenate([np.repeat([1], 84), np.repeat([2], 18), np.repeat([3], 12), np.repeat([4], 4), np.repeat([5], 12), np.repeat([random.randint(6,9)], 5), np.repeat([random.randint(10,19)], 7), np.repeat([random.randint(20,20)], 12)], axis=0) frequencies, edges = np.histogram(values, 20) hv.Histogram(frequencies, edges)
WARNING:root:Histogram: Histogram edges should be supplied as a tuple along with the values, passing the edges will be deprecated in holoviews 2.0. :Histogram [x] (Frequency)
ploty の API を 直接使用する
以下、のコードで
import numpy as np import plotly.plotly as py import plotly.graph_objs as go import random import plotly.offline as offline offline.init_notebook_mode() # ヒストグラムの値 区間決定後の値 を np.repeat、np.concatenate を使って再度集計 values = tuple(np.concatenate([np.repeat([1], 84), np.repeat([2], 18), np.repeat([3], 12), np.repeat([4], 4), np.repeat([5], 12), np.repeat([random.randint(6,9)], 5), np.repeat([random.randint(10,19)], 7), np.repeat([random.randint(20,20)], 12)], axis=0)) data = go.Histogram(x=values, xbins=dict(start=0, end=20, size=1)) # 区間の指定。sizeが区間幅 # レイアウトの指定 layout = go.Layout( xaxis = dict(title="value", dtick=10), yaxis = dict(title="count"), bargap = 0.1) fig = dict(data=[data], layout=layout) offline.iplot(fig)
まとめ
区間決定後の
実施した
グラフ描画ライブラリの、
既に
numpy の 変な
コメント